ddn.util.monaco.cache
TTL-based caching mechanism for performance optimization.
This module provides a generic, thread-safe cache implementation with time-to-live (TTL) support. It is designed to reduce the overhead of frequently accessing system information that doesn't change rapidly.
Copyright
Types 7
Exception thrown when cache operations fail.
this(string msg, string file = __FILE__, size_t line = __LINE__)Statistics about cache usage.
ulong hitsNumber of successful cache hitsulong missesNumber of cache missesulong evictionsNumber of entries evicted due to expirationsize_t sizeNumber of entries currently in the cacheulong totalStoredTotal number of entries ever storedConfiguration options for the cache.
A thread-safe, generic cache with TTL support.
This cache implementation stores values with associated time-to-live (TTL) values, automatically expiring entries when they become stale. It is designed to reduce the overhead of frequently querying system information.
Example:
auto cache = new Cache!CpuStats(dur!"seconds"(2));
cache.set("cpu", cpuStats());
auto stats = cache.get!("cpu");private CacheEntry!T[string] entriesprivate Mutex mutexprivate CacheStats statsprivate CacheConfig configprivate SysTime lastCleanupT getOrCompute(string key, T delegate() @safe compute, Duration ttl = Duration.zero) @safeGets a value from the cache, or computes and stores it if not present.this(Duration defaultTtl = dur!"seconds"(1), size_t maxSize = 0)Creates a new cache with the specified default TTL.this(CacheConfig cfg)Creates a new cache with the specified configuration.Global cache manager for system monitoring data.
This singleton class manages multiple caches for different types of system information, each with appropriate TTL values.
private CacheManager instanceprivate Mutex instanceMutexprivate Cache!ulong ulongCacheprivate Cache!double doubleCacheprivate Cache!string stringCacheprivate Mutex mutex