Registry / storage / cordova-file-cache

cordova-file-cache

JSON →
library1.2.2jsnpmunverified

Cordova File Cache is a library for caching remote files (images, documents, etc.) in Cordova/PhoneGap apps. It provides a promise-based API using CordovaPromiseFS and supports hash or mirror caching modes. Version 1.2.2 is the latest stable release. It requires cordova-plugin-file and optionally cordova-plugin-file-transfer. Unlike ad-hoc caching strategies, it offers a structured cache with readiness promises, progress tracking, and automatic server URL fallback. Release cadence is low; the package is stable but not actively maintained.

npm install cordova-file-cache
INSTALL
IMPORT
SIG · CORDOVA-FILE-CACHE
C
cordova-file-cache
storagejavascriptv1.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CordovaFileCache
✓ const CordovaFileCache = window.CordovaFileCache;
The library exposes a global CordovaFileCache object; no import statement is used. Include the script tag or bundle via <script src='CordovaFileCache.js'></script>.
CordovaPromiseFS
✓ const CordovaPromiseFS = window.CordovaPromiseFS;
Required dependency, also a global. Must be loaded before CordovaFileCache.
Cache instantiation
✓ var cache = new CordovaFileCache({ fs: new CordovaPromiseFS({ Promise: Promise }), mode: 'hash' });
✗ var cache = new CordovaFileCache({ mode: 'hash' }); // missing fs
The CordovaPromiseFS instance is mandatory and must include a Promise implementation.

Complete setup and usage example: initialize cache, add a file, download, and retrieve cached URL.

<!-- Include Cordova, plugins, and promise library first --> <script src="cordova.js"></script> <script src="bluebird.js"></script> <script src="CordovaPromiseFS.js"></script> <script src="CordovaFileCache.js"></script> <script> // Initialize cache after device ready document.addEventListener('deviceready', function() { var cache = new CordovaFileCache({ fs: new CordovaPromiseFS({ Promise: Promise // using native Promise or bluebird }), mode: 'hash', localRoot: 'cache', serverRoot: 'https://example.com/files/', cacheBuster: true }); cache.ready.then(function(cachedList) { console.log('Cache ready, cached paths:', cachedList); // Add files cache.add('photo1.jpg'); // prepends serverRoot cache.download().then(function(cache) { var internalUrl = cache.get('photo1.jpg'); // internalUrl like 'cdvfile://localhost/persistent/cache/xxx.jpg' console.log('Cached file URL:', internalUrl); }); }); }); </script>
Debug
Known issues
gotchaCordovaPromiseFS instance is required and must include a Promise implementation.
fix
Always provide fs option with a CordovaPromiseFS that has Promise property.
affects: >=1.0.0
gotchaFor iOS, Cordova 3.7.0 or higher is required due to a bug in requestFileSystem.
fix
Update Cordova to >=3.7.0.
affects: >=1.0.0
gotchaWhen using 'mirror' mode, serverRoot is required.
fix
Provide serverRoot option in constructor or use 'hash' mode.
affects: >=1.0.0
gotchaThe library uses global window.CordovaFileCache; not a module system.
fix
Load via script tags; not compatible with ES imports or CommonJS.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'root' of undefined
CordovaPromiseFS instance not provided or not initialized properly (missing directory).
fix
Ensure fs is a valid CordovaPromiseFS instance and that cordova-plugin-file is installed.
CordovaPromiseFS is not defined
CordovaPromiseFS.js script not loaded before CordovaFileCache.js.
fix
Include CordovaPromiseFS.js before CordovaFileCache.js.
TypeError: cache.download is not a function
Cache object not properly initialized or mode is invalid.
fix
Check constructor options: ensure fs and mode are correct.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
cordova-promise-fsrequiredRequired for file system operations (CordovaPromiseFS instance)
cordova-plugin-filerequiredRequired Cordova plugin for file access
Agent activity
17 hits · last 30 days
node
16
Resources
cordova-file-cache — npm install cordova-file-cache · libregistry