#pragma once #ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_CACHEENTRY_H_ #define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_CACHEENTRY_H_ #include #include #include #include namespace blockstore { namespace caching { template class CacheEntry final { public: explicit CacheEntry(Value value): _lastAccess(currentTime()), _value(std::move(value)) { } CacheEntry(CacheEntry &&) = default; double ageSeconds() const { return ((double)(currentTime() - _lastAccess).total_nanoseconds()) / ((double)1000000000); } Value releaseValue() { return std::move(_value); } private: boost::posix_time::ptime _lastAccess; Value _value; static boost::posix_time::ptime currentTime() { return boost::posix_time::microsec_clock::local_time(); } DISALLOW_COPY_AND_ASSIGN(CacheEntry); }; } } #endif