Baseflow / Baseflow/flutter_cached_network_image

Changing the cache duration (maxAgeCacheObject of the CacheManager)

Open
#224 2 comments 10 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
2.6k
Forks
731
Avg merge
3d 9h
Merged PRs (30d)
1

Description

Is it possible to change the cache duration easily?

I see that `BaseCacheManager` has default cache duration as 30 days (`Duration maxAgeCacheObject = const Duration(days: 30)`), but I would like to have the cache duration as 30 minutes.

I tried to create a new cache manager, which extends `BaseCacheManager` and overwrites the `maxAgeCacheObject`

```
class ImageCacheManager extends BaseCacheManager {
static const key = "libCachedImageData";

static ImageCacheManager _instance;

/// The DefaultCacheManager that can be easily used directly. The code of
/// this implementation can be used as inspiration for more complex cache
/// managers.
factory ImageCacheManager() {
if (_instance == null) {
_instance = new ImageCacheManager._();
}
return _instance;
}

ImageCacheManager._() : super(key, maxAgeCacheObject: Duration(minutes: 30));

Future getFilePath() async {
var directory = await getTemporaryDirectory();
return p.join(directory.path, key);
}
}
```

But still, the images are being cached for more than 30 minutes.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.