libcryfs/implementations/caching/CacheEntry.h

49 lines
899 B
C
Raw Normal View History

#pragma once
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_
#include <ctime>
#include <memory>
#include <messmer/cpp-utils/macros.h>
namespace blockstore {
class Block;
namespace caching {
class CacheEntry {
public:
CacheEntry(std::unique_ptr<Block> block): _lastAccess(time(nullptr)), _block(std::move(block)) {
}
CacheEntry(CacheEntry &&) = default;
double ageSeconds() const {
return difftime(time(nullptr), _lastAccess);
}
std::unique_ptr<Block> releaseBlock() {
return std::move(_block);
}
2015-04-15 20:39:58 +02:00
void setNextEntry(const CacheEntry *entry) {
_nextEntry = entry;
}
const CacheEntry *nextEntry() {
return _nextEntry;
}
private:
time_t _lastAccess;
std::unique_ptr<Block> _block;
2015-04-15 20:39:58 +02:00
const CacheEntry *_nextEntry;
DISALLOW_COPY_AND_ASSIGN(CacheEntry);
};
}
}
#endif