The docs for angular-cache 2.x.x are being deprecated. Please consider upgrading to 3.x.x
Fork me on GitHub

angular-cache

Angular-cache is a very useful replacement for Angular's $cacheFactory.

What is angular-cache?

Angular-cache is a feature-packed drop-in replacement for Angular's $cacheFactory. $cacheFactory is small and useful, but it's missing many needed features that today's single-page apps require. Check it out:

$cacheFactory vs $angularCacheFactory

$cacheFactory
// Angular's $cacheFactory
app.service('myService', function ($cacheFactory) {

    // This is the extent of $cacheFactory's configuration
    $cacheFactory('myNewCache', {

        // This cache can hold 1000 items
        capacity: 1000
    });

});
$angularCacheFactory
// Smarter caching with $angularCacheFactory
app.service('myService', function ($angularCacheFactory) {

    $angularCacheFactory('myNewCache', {

        // This cache can hold 1000 items
        capacity: 1000,

        // Items added to this cache expire after 15 minutes
        maxAge: 900000,

        // Items will be actively deleted when they expire
        deleteOnExpire: 'aggressive',

        // This cache will check for expired items every minute
        recycleFreq: 60000,

        // This cache will clear itself every hour
        cacheFlushInterval: 3600000,

        // This cache will sync itself with localStorage
        storageMode: 'localStorage',

        // Custom implementation of localStorage
        storageImpl: myLocalStoragePolyfill,

        // Full synchronization with localStorage on every operation
        verifyIntegrity: true,

        // This callback is executed when the item specified by "key" expires.
        // At this point you could retrieve a fresh value for "key"
        // from the server and re-insert it into the cache.
        onExpire: function (key, value) {

        }
     });

});
Master
Version Bower version
Build Status Build Status
Coverage Coverage Status
Code Climate Code Climate
Dependency Status Dependency Status

Angular-cache is tested with the following versions of Angular.js:

  • 1.0.4
  • 1.0.5
  • 1.0.6
  • 1.0.7
  • 1.0.8
  • 1.1.4
  • 1.1.5
  • 1.2.1
  • 1.2.2
  • 1.2.3
  • 1.2.4
  • 1.2.5
  • 1.2.6
  • 1.2.7

Installation

Installation - Read how to install angular-cache and get it running in your application.

Guide

Guide - Learn how to use angular-cache and read about common usage patterns.

API

API - Reference API documentation for angular-cache.

Community

Mailing List - Ask questions and get help.

Issues - Found a bug? Submit an issue!

GitHub - View the source code for angular-cache.