mcache_dart 0.1.10 copy "mcache_dart: ^0.1.10" to clipboard
mcache_dart: ^0.1.10 copied to clipboard

In-memory cache for Dart with LRU eviction, absolute/sliding/change-token expiration, priority eviction, byte-size limits, and anti-stampede GetOrCreate.

example/main.dart

import 'package:mcache_dart/mcache_dart.dart';

void main() {
  // Create a cache with a 1 MB size limit
  final cache = MemoryCache(MemoryCacheOptions(sizeLimit: 1 * 1024 * 1024));

  // Store with absolute expiration
  cache.set('key1', 'value1', MemoryCacheEntryOptions()
    ..absoluteExpirationRelativeToNow = const Duration(minutes: 5));

  // Retrieve
  final value = cache.get('key1');
  print('key1 = $value'); // prints: key1 = value1

  // Get-or-create (anti-stampede)
  final created = cache.getOrCreate('key2', () => 'default_value');
  print('key2 = $created'); // prints: key2 = default_value

  // Check statistics
  print('Hits: ${cache.stats.totalHits}, '
      'Misses: ${cache.stats.totalMisses}, '
      'Count: ${cache.count}');

  // Invalidate
  cache.remove('key1');

  // Priority-based eviction
  cache.set('low', 'low_value', MemoryCacheEntryOptions()
    ..priority = CacheItemPriority.low);
  cache.set('high', 'high_value', MemoryCacheEntryOptions()
    ..priority = CacheItemPriority.high);

  // Cleanup
  cache.dispose();
}
0
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publisherpurplesoft.io

Weekly Downloads

In-memory cache for Dart with LRU eviction, absolute/sliding/change-token expiration, priority eviction, byte-size limits, and anti-stampede GetOrCreate.

Repository (GitHub)
View/report issues

Topics

#cache #caching #memory #lru #flutter

License

AGPL-3.0 (license)

Dependencies

meta

More

Packages that depend on mcache_dart