removeOversized method
Remove data from storage until the storage file size is less than
maxCacheSize
.
Implementation
@override
Future<List<DatabaseData>> removeOversized(int maxCacheSize) async {
final removedData = <DatabaseData>[];
final db = await _getDb();
final file = File(db.path);
while (file.lengthSync() > maxCacheSize) {
final maps = await db.query(
_cacheTable,
orderBy: '$_lastUsedAt, $_useCount',
limit: 1,
);
if (maps.isEmpty) break;
final dbData = DatabaseData.fromJson(maps.first);
removedData.add(dbData);
await remove(
dbData.key,
dbData.queryParams,
rebuildDb: true,
);
}
return removedData;
}