quantum_cache library
quantum_cache — A blazing-fast, pure-Dart dual-layer cache for Flutter.
Quick Start
// Register custom adapters BEFORE init
SuperCache.registerAdapter(UserAdapter());
// Initialize once at app startup
await SuperCache.init(
config: const CacheConfig(
maxMemoryEntries: 2000,
defaultTtl: Duration(hours: 24),
evictionPolicy: EvictionPolicyType.arc,
enableStatistics: true,
),
);
final cache = SuperCache.instance;
// Write
await cache.put('greeting', 'Hello, world!');
await cache.put('user', myUser, ttl: const Duration(hours: 1));
// Read
final greeting = await cache.get<String>('greeting'); // nullable
// Cache-aside pattern
final config = await cache.getOrPut(
'app_config',
() => fetchConfigFromServer(),
ttl: const Duration(minutes: 30),
);
// Statistics
print(cache.statistics);
// Clean up
await cache.dispose();
Named instances
await SuperCache.init(name: 'session', config: CacheConfig(boxName: 'session'));
final session = SuperCache.named('session');
Encryption
final key = AesCipher.generateKey(); // store securely!
await SuperCache.init(
config: CacheConfig(encryptionKey: key),
);
Classes
- AesCipher
- AES-256-GCM authenticated encryption cipher for quantum_cache.
- ArcPolicy
- Adaptive Replacement Cache (ARC) eviction policy.
- BinaryReader
- A fast, sequential binary data reader that wraps a Uint8List.
- BinaryWriter
- A fast, sequential binary data writer backed by a growable byte list.
- ByteUtils
- Utility functions for working with raw byte arrays.
- Cacheable
- Marks a class as serializable by quantum_cache's code generator.
- CacheConfig
- Full configuration for a SuperCache instance.
- CacheField
-
Marks a field in a
@Cacheableclass for inclusion in the generated adapter. - CacheKey
- Optional annotation to mark a field as the primary key.
- CacheStatistics
- Snapshot of live performance metrics for a SuperCache instance.
- CacheStatisticsSnapshot
- An immutable snapshot of CacheStatistics at a specific point in time.
- Crc32
- Stand-alone CRC-32 (IEEE 802.3 polynomial) utility.
- EvictionPolicy
- Abstract interface for L1 cache eviction policies.
- HashUtils
- Fast, non-cryptographic hash functions for internal use.
- LfuPolicy
- Least Frequently Used eviction policy.
- LruPolicy
- Least Recently Used eviction policy.
- NullCipher
- Null cipher — returns data unchanged.
- SuperCache
- The primary entry point for quantum_cache.
-
SuperCacheAdapter<
T> - Defines how a custom Dart type is serialized to and from bytes.
- SuperCacheBase
- Abstract interface that every quantum_cache implementation must satisfy.
- SuperCacheCipher
- Abstract contract for quantum_cache encryption backends.
- TypeRegistry
- A global registry mapping type IDs and Dart Types to SuperCacheAdapters.
- XorCipher
- XOR stream cipher for maximum-speed, low-security encryption.
Enums
- CacheLogLevel
- Log verbosity levels for quantum_cache's internal logger.
- EvictionPolicyType
- Supported eviction policy types.
Exceptions / Errors
- AdapterConflictException
-
Thrown when a registered adapter
typeIdconflicts with an existing one. - CacheCodecException
- Thrown when encoding or decoding a value fails.
- CacheCorruptedException
- Thrown when the cache data file on disk is corrupted.
- CacheEncryptionException
- Thrown when encryption or decryption fails.
- CacheInitializationException
- Thrown when cache initialization fails (e.g. disk not accessible).
- CacheNotInitializedException
- Thrown when a SuperCache instance is used before SuperCache.init is called.
- CacheStorageException
- Thrown when a disk read or write operation fails.
- ChecksumMismatchException
- Thrown when a checksum (CRC32) verification fails for a stored entry.
- DiskCapacityExceededException
- Thrown when the disk cache exceeds the configured CacheConfig.maxDiskSizeBytes.
- InvalidConfigException
- Thrown when a CacheConfig contains invalid or contradictory settings.
- InvalidKeyException
- Thrown when an invalid encryption key is supplied (e.g. wrong length).
- IsolateException
- Thrown when an Isolate communication error occurs.
- MissingAdapterException
- Thrown when no SuperCacheAdapter is registered for a given type.
- SuperCacheException
- Root exception for all quantum_cache errors.