put method
Stores a value in the cache using the default driver.
The key must be a non-empty string. The value can be any serializable
object. The ttl specifies how long the item should remain in the cache.
Throws CacheException if the key is empty or if the operation fails.
Implementation
@override
Future<void> put(String key, dynamic value, Duration ttl) async {
_validator.validateKey(key);
_validator.validateTtl(ttl);
try {
final driver = _driverRegistry.getDefaultDriver();
await driver.put(key, value, ttl);
_statisticsManager.updateStats(
_driverRegistry.getDefaultDriverName(),
hit: false,
operation: 'put',
);
} catch (e) {
_statisticsManager.updateStats(
_driverRegistry.getDefaultDriverName(),
hit: false,
operation: 'put',
error: true,
);
throw CacheException('Failed to store cache item "$key": $e');
}
}