add method

  1. @override
Future<bool> add(
  1. String key,
  2. dynamic value,
  3. Duration ttl
)
override

Stores a value in the cache if the key does not exist.

Returns true if the item was actually added, false otherwise.

  • Parameters:
    • key: A non-null, non-empty string representing the cache key.
    • value: The data to be cached.
    • ttl: The duration for which the item should remain in the cache.

Implementation

@override
Future<bool> add(String key, dynamic value, Duration ttl) async {
  if (await has(key)) {
    return false;
  }
  await put(key, value, ttl);
  return true;
}