set method

Future<void> set(
  1. String key,
  2. String filePath,
  3. int size
)

Implementation

Future<void> set(String key, String filePath, int size) async {
  try {
    final file = File(filePath);
    if (!await file.exists()) return;

    final dest = '${_dir.path}/${key}_${DateTime.now().millisecondsSinceEpoch}';
    await file.copy(dest);

    final entry = CacheEntry(
      key: key,
      localPath: dest,
      size: size,
      cachedAt: DateTime.now(),
      lastAccessedAt: DateTime.now(),
    );
    await _box.put(key, entry.toJson());
    await _enforceLimit();
  } catch (e) {
    CloudLogger.error('Cache set failed key=$key', error: e);
  }
}