put<T> method
Puts a cache entry
Implementation
Future<void> put<T>(
String key,
T data, {
DataCacheOptions options = const DataCacheOptions(),
}) async {
final fullKey = _getFullKey(key);
try {
// Serialize the data
final bytes = _serializeData(data);
// Compress the data if needed
final finalBytes =
options.compress
? _dataChunker.compressData(bytes)
: Uint8List.fromList(bytes);
// Store the data in cache
await _dataCache.put<Uint8List>(
fullKey,
finalBytes,
policy: CachePolicy(expiry: options.maxAge),
);
logger?.info('Cached entry $key (${_formatSize(finalBytes.length)})');
} catch (e) {
logger?.error('Error caching entry $key: $e');
rethrow;
}
}