diff options
Diffstat (limited to 'zenstore/include')
| -rw-r--r-- | zenstore/include/zenstore/gc.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h index 94f3c32ac..b30c70b1f 100644 --- a/zenstore/include/zenstore/gc.h +++ b/zenstore/include/zenstore/gc.h @@ -25,13 +25,28 @@ class CasGc; class CidStore; struct IoHash; +/** GC clock + */ +class GcClock +{ +public: + using Clock = std::chrono::system_clock; + using TimePoint = Clock::time_point; + using Duration = Clock::duration; + using Tick = int64_t; + + static Tick TickCount() { return Now().time_since_epoch().count(); } + static TimePoint Now() { return Clock::now(); } + static TimePoint TimePointFromTick(const Tick TickCount) { return TimePoint{Duration{TickCount}}; } +}; + /** Garbage Collection context object */ class GcContext { public: - GcContext(); + GcContext(GcClock::TimePoint Time = GcClock::Now()); ~GcContext(); void ContributeCids(std::span<const IoHash> Cid); @@ -48,6 +63,13 @@ public: bool IsContainerGcEnabled() const; void SetContainerGcEnabled(bool NewState); + GcClock::TimePoint Time() const; + + GcClock::Duration MaxCacheDuration() const; + void MaxCacheDuration(GcClock::Duration Duration); + + inline bool Expired(GcClock::Tick TickCount) { return Time() - GcClock::TimePointFromTick(TickCount) > MaxCacheDuration(); } + private: struct GcState; |