Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/src/cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef ExpirationCallback = void Function(String key);
/// CacheManager class to handle caching operations with optional TTL (Time-To-Live).
/// It also supports encryption, backup, and restore functionalities.
class CacheManager {
static final CacheManager _instance = CacheManager._internal();
static Database? _database;
final encrypt.Encrypter _encrypter =
encrypt.Encrypter(encrypt.AES(encrypt.Key.fromLength(32)));
Expand Down Expand Up @@ -130,6 +129,16 @@ class CacheManager {
await db.delete('cache');
}

/// Deletes all the expired cache entries based on ttl.
///
/// Returns the number of entries deleted.
Future<int> deleteExpiredCache() async {
final db = await database;
return await db.delete('cache',
where: 'ttl != NULL && ttl < ?',
whereArgs: [DateTime.now().millisecondsSinceEpoch]);
}

/// Backs up cache data to a specified file path.
Future<void> backupCache(String backupPath) async {
final db = await database;
Expand Down