My app uses flutter_cache_manger to download all files to local device so these can be used offline. Recently I figured that on samsung devices the plugin is working very strangely. The cache is cleared automatically after 25000 files or the files which were downloaded on start are replaced by new files. I tested it on 2 different samsung tablets and a samsung phone. I have around 30000 files to be downloaded. I have tested app on my One Plus 6t all files download on it and remains there.
On my One Plus 6t
Same app on Samsung M20
Refer to samsung screenshots, the cache was cleared automatically while the download was in progress. This should not happen. I have extended flutter_cache_manager to keep files for 5 year and save 50000 files. Here is the code for it.
class MyCacheManager extends BaseCacheManager {
static const key = "suryagoldscache";
static MyCacheManager _instance;
factory MyCacheManager() {
if (_instance == null) {
_instance = new MyCacheManager._();
}
return _instance;
}
MyCacheManager._()
: super(key,
maxAgeCacheObject: Duration(days: 1825),
maxNrOfCacheObjects: 50000,
fileFetcher: _myHttpGetter);
@override
Future<String> getFilePath() async {
var directory = await getTemporaryDirectory();
return path.join(directory.path, key);
}
static Future<FileFetcherResponse> _myHttpGetter(String url,
{Map<String, String> headers}) async {
HttpFileFetcherResponse response;
try {
var res = await http.get(url, headers: headers);
res.headers.addAll({'cache-control': 'private, max-age=157680000'});
response = HttpFileFetcherResponse(res);
} on SocketException {
// print('No internet connection');
}
return response;
}
}





