#pragma once #ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_ #define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_ #include #include #include #include namespace blockstore { class Block; namespace caching { class CacheEntry { public: CacheEntry(std::unique_ptr block): _lastAccess(currentTime()), _block(std::move(block)) { } CacheEntry(CacheEntry &&) = default; double ageSeconds() const { return ((double)(currentTime() - _lastAccess).total_nanoseconds()) / ((double)1000000000); } std::unique_ptr releaseBlock() { return std::move(_block); } void setNextEntry(const CacheEntry *entry) { _nextEntry = entry; } const CacheEntry *nextEntry() { return _nextEntry; } private: boost::posix_time::ptime _lastAccess; std::unique_ptr _block; const CacheEntry *_nextEntry; static boost::posix_time::ptime currentTime() { return boost::posix_time::microsec_clock::local_time(); } DISALLOW_COPY_AND_ASSIGN(CacheEntry); }; } } #endif