Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[How to use] How does cacheKey work? #48

Open
delfme opened this issue Mar 4, 2023 · 0 comments
Open

[How to use] How does cacheKey work? #48

delfme opened this issue Mar 4, 2023 · 0 comments

Comments

@delfme
Copy link

delfme commented Mar 4, 2023

Platforms

dart

Description

Hello! I have a doubt about cacheKey.

/// Clear the disk cache image then return if it succeed.
Future<bool> clearDiskCachedImage(String url, {String? cacheKey}) async {
try {
final File? file = await getCachedImageFile(url, cacheKey: cacheKey);
if (file != null) {
await file.delete(recursive: true);
}
} catch (_) {
return false;
}
return true;
}
/// Get the local file of the cached image
Future<File?> getCachedImageFile(String url, {String? cacheKey}) async {
try {
final String key = cacheKey ?? keyToMd5(url);
final Directory cacheImagesDirectory = Directory(
join((await getTemporaryDirectory()).path, cacheImageFolderName));
if (cacheImagesDirectory.existsSync()) {
await for (final FileSystemEntity file in cacheImagesDirectory.list()) {
if (file.path.endsWith(key)) {
return File(file.path);
}
}
}
} catch (_) {
return null;
}
return null;
}

I'd need to save many images to disk and then delete them all at once without passing their urls.
I thought that cacheKey was intended for that purpose, like assigning to [url_1..url_100] the same cackeKey (ie. "profiles") and then clearDiskCachedImage("profiles") to delete from disk all these 100 files that were cached when loading profiles screens.

But from code above, it doesnt seem to work this way. Can you please shed some light on this?
Thx

My code

No response

Try do it

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant