Skip to content

vyuh_cache ​

Cache<V> wraps a CacheStorage<V> implementation with a configured TTL. Use it to reuse an expensive result while it remains valid. It is independent of the content system.

How the pieces fit together

Use the cache ​

dart
import 'package:vyuh_cache/vyuh_cache.dart';

Future<void> main() async {
  final cache = Cache<String>(CacheConfig(
    storage: MemoryCacheStorage<String>(),
    ttl: const Duration(minutes: 5),
  ));
  final greeting = await cache.build(
    'greeting',
    generateValue: () async => 'Hello, Vyuh.',
  );
  print(greeting);
  await cache.remove('greeting');
}

Choose an operation ​

OperationBehavior
getReturn an unexpired value, or null
hasCheck whether an unexpired entry exists
buildRetrieve or generate; concurrent misses share generation
setStore a value with the configured TTL
removeDelete one key
clearClear stored entries

Storage failure during build does not discard a freshly generated value. Generator failures propagate so callers can handle them and retry. get and explicit storage operations expose storage failures to callers.

Memory storage removes expired entries when accessed. Set MemoryCacheStorage<String>(maxEntries: 500) to bound it with least recently used eviction; omitting the limit keeps the existing unbounded policy. remove, clear, and explicit set prevent older generators from writing back into the cache. Existing callers can still receive the generated result: invalidation does not cancel the underlying operation.

See all cache declarations and performance and correctness.