get<T> method

Future<T?> get<T>(
  1. String key, {
  2. String? storageType,
})

Gets a cache entry

Implementation

Future<T?> get<T>(String key, {String? storageType}) async {
  final fullKey = _getFullKey(key);

  try {
    // Try to get the data from cache
    final cachedData = await _dataCache.get<Uint8List>(fullKey);

    if (cachedData != null) {
      // Decompress the data if needed
      final decompressedData =
          _isCompressed(cachedData)
              ? _dataChunker.decompressData(cachedData)
              : cachedData;

      // Deserialize the data
      final data = _deserializeData<T>(decompressedData);

      logger?.fine('Cache hit: $key');
      return data;
    }

    logger?.fine('Cache miss: $key');
    return null;
  } catch (e) {
    logger?.error('Error getting cache entry $key: $e');
    return null;
  }
}