get method

  1. @override
Future<CacheItem?> get(
  1. String key
)
override

Retrieves the CacheItem associated with the given key.

Returns null if no value is found for the given key.

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

Implementation

@override
Future<CacheItem<dynamic>?> get(String key) async {
  final p = await prefs;
  final String? encryptedValue = p.getString(_getKey(key));
  if (encryptedValue == null) {
    return null;
  }
  dynamic value;
  if (enableEncryption) {
    final decryptedValue = _decrypt(encryptedValue);
    value = jsonDecode(decryptedValue);
  } else {
    final jsonString = encryptedValue;
    final Map<String, dynamic> map = jsonDecode(jsonString);
    value = map;
  }
  return CacheItem<dynamic>(
    value: value['value'],
    expiry: value['expiry'] != null
        ? DateTime.fromMillisecondsSinceEpoch(value['expiry'] as int)
        : null,
  );
}