getKeys method
Returns a list of all keys in the cache.
Throws a CacheException if there is an error retrieving the keys.
The limit
and offset
parameters can be used to paginate the results.
Implementation
@override
Future<List<String>> getKeys({int? limit, int? offset}) async {
final p = await prefs;
final keys = p.getKeys();
final filteredKeys = keys
.where((key) => key.startsWith('${boxName ?? 'data_cache_x'}_'))
.map((key) => key.substring('${boxName ?? 'data_cache_x'}_'.length))
.toList();
if (limit == null && offset == null) {
return filteredKeys;
}
final startIndex = offset ?? 0;
final endIndex = limit == null ? filteredKeys.length : startIndex + limit;
return filteredKeys.skip(startIndex).take(endIndex - startIndex).toList();
}