add method

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

Stores an item in the cache only if key is absent (or expired).

Unlike put, this never replaces an existing, unexpired entry, so concurrent callers cannot clobber each other's values. Stores should implement this atomically (e.g. exclusive file creation, SET NX).

Returns true if the item was stored, false if key already holds an unexpired value.

Implementation

@override
Future<bool> add(String key, dynamic value, int seconds) async {
  final response = await _request(
    'add',
    key: key,
    payload: <String, Object?>{'value': value, 'seconds': seconds},
  );
  return response['stored'] == true;
}