2015-04-15 15:46:35 +02:00
|
|
|
#pragma once
|
2015-04-16 14:10:44 +02:00
|
|
|
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_
|
|
|
|
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_
|
2015-04-15 15:46:35 +02:00
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <memory>
|
|
|
|
#include <messmer/cpp-utils/macros.h>
|
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
class Block;
|
2015-04-16 14:10:44 +02:00
|
|
|
namespace caching {
|
2015-04-15 15:46:35 +02:00
|
|
|
|
|
|
|
class CacheEntry {
|
|
|
|
public:
|
|
|
|
CacheEntry(std::unique_ptr<Block> block): _lastAccess(time(nullptr)), _block(std::move(block)) {
|
|
|
|
}
|
|
|
|
|
2015-04-15 19:05:58 +02:00
|
|
|
CacheEntry(CacheEntry &&) = default;
|
|
|
|
|
|
|
|
double ageSeconds() const {
|
2015-04-15 15:46:35 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-15 15:46:35 +02:00
|
|
|
private:
|
|
|
|
time_t _lastAccess;
|
|
|
|
std::unique_ptr<Block> _block;
|
2015-04-15 20:39:58 +02:00
|
|
|
const CacheEntry *_nextEntry;
|
2015-04-15 15:46:35 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CacheEntry);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|