put method

  1. @override
Future<void> put(
  1. String key,
  2. CacheItem item
)
override

Stores a value in the cache with the given key.

The value is wrapped in a CacheItem object, which allows for optional expiry.

Throws a CacheException if there is an error storing the data.

Implementation

@override
Future<void> put(String key, CacheItem<dynamic> item) async {
  final p = await prefs;
  dynamic value = {
    'value': item.value,
    'expiry': item.expiry?.millisecondsSinceEpoch,
  };
  String jsonString = jsonEncode(value);
  if (enableEncryption) {
    jsonString = _encrypt(jsonEncode(value));
  }
  await p.setString(_getKey(key), jsonString);
}