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

High-performance in-memory cache for Dart. LRU eviction, absolute/sliding/change-token expiration, priority eviction, byte-size limits, anti-stampede GetOrCreate, post-eviction callbacks.

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
140
points
153
downloads

Documentation

API reference

Publisher

verified publisherpurplesoft.io

Weekly Downloads

High-performance in-memory cache for Dart. LRU eviction, absolute/sliding/change-token expiration, priority eviction, byte-size limits, anti-stampede GetOrCreate, post-eviction callbacks.

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