Skip to content

Commit

Permalink
expose memoryCacheContainsKey method (PR by @vinicius0026: Baseflow#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
contactjavas committed Sep 18, 2023
1 parent ce0c61b commit f1fccad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flutter_cache_manager/lib/src/cache_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class CacheStore {
}
}

bool memoryCacheContainsKey(String key) {
return _memCache.containsKey(key);
}

Future<void> dispose() async {
if (_scheduledCleanup != null) {
_scheduledCleanup?.cancel();
Expand Down
17 changes: 17 additions & 0 deletions flutter_cache_manager/test/cache_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ void main() {
await store.getFile(fileUrl);
expect(await store.getFileFromMemory(fileUrl), isNotNull);
});

test(
'Store.memoryCacheContainsKey should return true if the key is present in the memory cache',
() async {
var config = createTestConfig();
var store = CacheStore(config);

var cacheObject = CacheObject(
'baseflow.com/test.png',
relativePath: 'testimage.png',
validTill: clock.now().add(const Duration(days: 7)),
);
await store.putFile(cacheObject);

expect(store.memoryCacheContainsKey('baseflow.com/test.png'), true);
expect(store.memoryCacheContainsKey('unseen-file'), false);
});
});

group('Storing files in store', () {
Expand Down

0 comments on commit f1fccad

Please sign in to comment.