#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: explicit 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); } private: boost::posix_time::ptime _lastAccess; std::unique_ptr _block; static boost::posix_time::ptime currentTime() { return boost::posix_time::microsec_clock::local_time(); } DISALLOW_COPY_AND_ASSIGN(CacheEntry); }; } } #endif