imgcache.js
imgcache.js copied to clipboard
Cache file inside the application cache folder
Hi i would like to cache file inside the application cache folder (cordova.file.cacheDirectory) but, when i assign this value to "localCacheFolder" i get this error:
Code ImgCacheProvider.setOptions({ debug: true, localCacheFolder: cordova.file.cacheDirectory, usePersistentCache: true });
Code "ERROR: Failed to get/create local cache directory: 5"
The probeme is that currently it stores image files in the "/storage/emulated/0/imgcache" folder and if i delete the app, the cached files are not deleted
I am looking forward to a solution for this as well.
i am getting same error as you.
What I did is I used the latest version of this package, i.e. instead of
bower install --save imgcache.js
I used
bower install --save imgcache.js#master
The master version includes a configurable option called cordovaFilesystemRoot
which I set to cordova.file.dataDirectory
or cordova.file.externalDataDirectory
- you can try using cacheDirectory
as well.
So this is what I do when the device is ready:
ImgCache.options = {
debug : true,
localCacheFolder : "imgCache", // name of the cache folder
useDataURI : false, // use src="data:.."? otherwise will use src="filesystem:.."
chromeQuota : 50*1024*1024, // allocated cache space : here 50MB
usePersistentCache : true, // false = use temporary cache storage
cacheClearSize : 0, // size in MB that triggers cache clear on init, 0 to disable
headers : {}, // HTTP headers for the download requests -- e.g: headers: { 'Accept': 'application/jpg' }
withCredentials : false, // indicates whether or not cross-site Access-Control requests should be made using credentials
skipURIencoding : false, // enable if URIs are already encoded (skips call to sanitizeURI)
cordovaFilesystemRoot : cordova.file.dataDirectory // if specified, use one of the Cordova File plugin's app directories for storage
};
ImgCache.$init();
Notice that the localCacheFolder
is only the name of the last folder, which will be created in the cordovaFilesystemRoot
, in my case cordova.file.dataDirectory
.