Repository navigation
Expand file tree
/
Copy pathdisk_cache.hpp
More file actions
41 lines (40 loc) · 1.82 KB
/
Copy pathdisk_cache.hpp
File metadata and controls
41 lines (40 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
#include "recording_source.hpp"
#include <string>
namespace lvm {
enum class CacheKind { ScanIndex,Overview,FilterState };
// Payload + maximum temporary output, across both kinds. Live leases are pinned.
// One process owns the directory until the last manager/lease has gone away.
class DiskCache {
struct State;
struct Entry;
public:
class Lease {
public:
~Lease();
Lease(const Lease&)=delete;
Lease& operator=(const Lease&)=delete;
const std::filesystem::path& path() const;
void commit(); // Closed, complete output only; converts quota to actual bytes.
void discard(); // Invalid artifacts cannot be found again; pins still protect I/O.
private:
friend class DiskCache;
Lease()=default;
std::shared_ptr<State> state_;
std::shared_ptr<Entry> entry_;
};
explicit DiskCache(const std::filesystem::path& directory,
std::uint64_t max_bytes=2ULL*1024*1024*1024,std::size_t max_entries=256);
// Private bounded fallback. The last manager/lease removes only owned files.
static std::shared_ptr<DiskCache> temporary(std::uint64_t max_bytes=2ULL*1024*1024*1024,std::size_t max_entries=256);
std::shared_ptr<Lease> find(const std::string& key,CacheKind kind);
std::shared_ptr<Lease> begin_write(const std::string& key,CacheKind kind,std::uint64_t maximum_bytes);
void set_limit(std::uint64_t bytes); // Refuses a limit below live pinned bytes.
std::uint64_t used_bytes() const; // Includes reserved maximum temporary outputs.
std::size_t entry_count() const;
const std::filesystem::path& directory() const;
private:
std::shared_ptr<State> state_;
};
std::string recording_cache_key(const std::filesystem::path& source,RecordingStamp stamp,const std::string& variant);
} // namespace lvm