Registry / storage / angular-cache

angular-cache

JSON →
library4.6.0jsnpmunverified

angular-cache v4.6.0 is an advanced replacement for Angular's $cacheFactory, designed for Angular 1.x applications. It supports time-based expiration, localStorage/sessionStorage backends, LRU eviction, and custom storage adapters. Unlike $cacheFactory, it offers features like item 'touch', expiry callbacks, cache disable/enable, and bulk operations across caches. It is distributed via npm and Bower. Maintenance mode as AngularJS itself is in LTS; last release was 2017.

npm install angular-cache
INSTALL
IMPORT
SIG · ANGULAR-CACHE
A
angular-cache
storagejavascriptv4.6.0
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.

angular-cache module
angular.module('myApp', ['angular-cache'])
angular.module('myApp', ['angularCache'])
Module name is 'angular-cache' (kebab-case), not 'angularCache' (camelCase).
CacheFactoryProvider
angular.module('myApp', ['angular-cache']).config(function(CacheFactoryProvider) { ... })
angular.module('myApp', []).config(function(CacheFactoryProvider) { ... })
Must include 'angular-cache' module dependency to inject CacheFactoryProvider.
CacheFactory
app.service('MyService', function(CacheFactory) { ... })
const CacheFactory = require('angular-cache').CacheFactory
CacheFactory is an Angular service, not a direct export from the npm package. Always inject into Angular components.

Demonstrates basic setup, default configuration via CacheFactoryProvider, creating a cache with localStorage, and using it with $http.

// Install: npm install angular-cache // In your AngularJS app: angular.module('myApp', ['angular-cache']) .config(function(CacheFactoryProvider) { // Set default options angular.extend(CacheFactoryProvider.defaults, { maxAge: 15 * 60 * 1000, // 15 minutes deleteOnExpire: 'aggressive', recycleFreq: 60000 }); }) .service('BookService', function(CacheFactory, $http) { // Create cache only if not exists if (!CacheFactory.get('bookCache')) { CacheFactory.createCache('bookCache', { storageMode: 'localStorage', capacity: 100 }); } var bookCache = CacheFactory.get('bookCache'); return { findBookById: function(id) { return $http.get('/api/books/' + id, { cache: bookCache }); } }; });
Debug
Known issues
breakingVersions below 4.0.0 have deprecated APIs. Upgrade to 4.x for the current API.
fix
Update to 4.6.0 (latest). Review the CHANGELOG for migration details.
affects: <4.0.0
deprecatedThe package is in maintenance mode as AngularJS is in LTS. No new features are expected.
fix
Consider migrating to Angular (2+) with a modern caching library like ngx-cache or localForage.
affects: >=4.0.0
gotchaCacheFactory.get('cacheName') returns null if cache does not exist. Do not assume it exists after createCache.
fix
Always check existence before use: if (!CacheFactory.get('myCache')) { CacheFactory.createCache('myCache', ...); } var cache = CacheFactory.get('myCache');
affects: >=4.0.0
gotchaUsing CacheFactory('name') as a setter is deprecated. Use CacheFactory.createCache('name', options).
fix
Replace CacheFactory('myCache', {...}) with CacheFactory.createCache('myCache', {...}).
affects: >=4.0.0
gotchaThe package does not support Angular 2+. It is only for AngularJS (1.x).
fix
Use a different caching library for Angular 2+ applications.
affects: >=4.0.0
Errors
Common errors & fixes
Error: $injector:unpr Unknown provider: CacheFactoryProviderProvider <- CacheFactoryProvider
Missing 'angular-cache' module dependency in the app module.
fix
Add 'angular-cache' as a dependency: angular.module('myApp', ['angular-cache']).
Error: CacheFactory('myCache') is deprecated. Use CacheFactory.createCache('myCache', options) instead.
Using CacheFactory as a constructor/setter, which is deprecated.
fix
Call CacheFactory.createCache('myCache', options) instead.
TypeError: Cannot read property 'put' of null
CacheFactory.get('myCache') returned null because the cache was not created or was destroyed.
fix
Ensure the cache exists before using it. Create it first: if (!CacheFactory.get('myCache')) { CacheFactory.createCache('myCache', ...); } then get it.
Upgrade
Version history
4.6.0latest on npm
Audit
Dependencies
angularrequiredpeer dependency for AngularJS app integration
Agent activity
44 hits · last 30 days
node
40
Resources
angular-cache — npm install angular-cache · libregistry