increment method

  1. @override
Future increment(
  1. String key, [
  2. dynamic value = 1
])
override

Increments the value of an item in the cache.

  • key: The key of the item to increment.
  • value: The amount by which to increment the item.

Returns the new value of the item.

Implementation

@override
Future<dynamic> increment(String key, [dynamic value = 1]) async {
  final namespaced = await _namespaced(key);
  final currentValue = await store.get(namespaced) ?? 0;
  final incrementValue = value is int ? value : 1;
  final newValue = (currentValue as num) + incrementValue;
  await store.put(namespaced, newValue, 0);
  return newValue;
}