Skip to content

Commit

Permalink
Merge pull request #469 from SmartVive/develop
Browse files Browse the repository at this point in the history
Fix removeCacheFile
  • Loading branch information
martijn00 authored Oct 9, 2024
2 parents 3d18fcf + 9d2dbe5 commit 515cc9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions flutter_cache_manager/lib/src/cache_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'dart:io' as io;

///Flutter Cache Manager
///Copyright (c) 2019 Rene Floor
Expand Down Expand Up @@ -184,7 +183,7 @@ class CacheStore {
if (_futureCache.containsKey(cacheObject.key)) {
await _futureCache.remove(cacheObject.key);
}
final file = io.File(cacheObject.relativePath);
final file = await fileSystem.createFile(cacheObject.relativePath);

if (file.existsSync()) {
try {
Expand Down
18 changes: 18 additions & 0 deletions flutter_cache_manager/test/cache_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,24 @@ void main() {
verify(config.mockRepo
.deleteAll(argThat(containsAll([co1.id, co2.id, co3.id])))).called(1);
});

test('Store should delete file when remove cached file', () async {
var config = createTestConfig();
var store = CacheStore(config);

await config.returnsFile(fileName);
config.returnsCacheObject(fileUrl, fileName, validTill, id: 1);

var cacheObject = await store.retrieveCacheData(fileUrl);

expect(cacheObject, isNotNull);
var fileInfo = await store.getFile(cacheObject!.key);
expect(await fileInfo?.file.exists(), isTrue);

await store.removeCachedFile(cacheObject);

expect(await fileInfo?.file.exists(), isFalse);
});
});
}

Expand Down

0 comments on commit 515cc9e

Please sign in to comment.