Example:
auto stats = cache.getOrCompute("cpu", &getCpuStats);T 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 is the most common pattern for using the cache. If the value is present and not expired, it is returned immediately. Otherwise, the provided delegate is called to compute the value, which is then cached.
key | Cache key |
compute | Delegate to compute the value if not cached |
ttl | Optional custom TTL (uses default if not specified) |
Example:
auto stats = cache.getOrCompute("cpu", &getCpuStats);