Skip to content

pdf/angular-cache

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-cache (0.7.2 - Alpha)

angular-cache is a caching system that improves upon the capabilities of the $cacheFactory provided by AngularJS. With angular-cache your caches can periodically clear themselves and flush items that have expired.

The goal of the project is to solve a general problem, not satisfy a specific scenario.

Table of Contents

  1. Features
  2. Demo
  3. Status
  4. Download
  5. Usage
  6. Roadmap
  7. Contributing
  8. License

Features

These are in addition to what Angular's $cacheFactory provides.

AngularCache

  • option: maxAge (AngularCache.put()): Set a default maximum lifetime on the item being added to the cache. It will be removed when it expires.

$angularCacheFactory

  • option: maxAge ($angularCacheFactory()): Set a default maximum lifetime on all items added to the cache. They will be removed when they expire. Can be configured on a per-item basis for greater specificity.
  • option: cacheFlushInterval ($angularCacheFactory()): Set the cache to periodically clear itself.
  • $angularCacheFactory.keySet(): Return the set of keys associated with all current caches owned by $angularCacheFactory.
  • $angularCacheFactory.keys(): Return an array of the keys associated with all current caches owned by $angularCacheFactory.

Demo

Demo

Status

Version Branch Build status Test Coverage
0.7.2 master Build Status Test Coverage
0.7.2 develop Build Status
0.7.2 all Build Status

Download

All Downloads (at drone.io)

or

Latest Stable Version

Type From drone.io From raw.github.com Size
Production angular-cache-0.7.2.min.js angular-cache-0.7.2.min.js 2.41 KB
Development angular-cache-0.7.2.js angular-cache-0.7.2.js 22.1 KB

Usage

Load angular-cache

Make sure angular-cache is included on your page after Angular.

angular.module('myApp', ['angular-cache']);

See angular-cache

Create a cache

angular.module('myApp').service('myService', ['$angularCacheFactory',
    function ($angularCacheFactory) {

        // create a cache with default settings
        var myCache = $angularCacheFactory('myCache');

        // create an LRU cache with a capacity of 10
        var myLRUCache = $angularCacheFactory('myLRUCache', {
            capacity: 10
        });

        // create a cache whose items have a maximum lifetime of 10 minutes
        var myTimeLimitedCache = $angularCacheFactory('myTimeLimitedCache', {
            maxAge: 600000
        });

        // create a cache that will clear itself every 10 minutes
        var myIntervalCache = $angularCacheFactory('myIntervalCache', {
            cacheFlushInterval: 600000
        });

        // create an cache with all options
        var myAwesomeCache = $angularCacheFactory('myAwesomeCache', {
            capacity: 10,
            maxAge: 600000,
            cacheFlushInterval: 600000
        });
    }
]);

See $angularCacheFactory

Retrieve a cache

angular.module('myApp').service('myOtherService', ['$angularCacheFactory',
    function ($angularCacheFactory) {

        var myCache = $angularCacheFactory.get('myCache');
    }
]);

See $angularCacheFactory#get

Retrieve items

myCache.get('someItem'); // { name: 'John Doe' });

// if the item is not in the cache or has expired
myCache.get('someMissingItem'); // undefined

See Cache#get

Add items

myCache.put('someItem', { name: 'John Doe' });

myCache.get('someItem'); // { name: 'John Doe' });

Give a specific item a maximum age

// The maxAge given to this item will override the maxAge of the cache, if any was set
myCache.put('someItem', { name: 'John Doe' }, { maxAge: 10000 });

myCache.get('someItem'); // { name: 'John Doe' });

// wait at least ten seconds
setTimeout(function() {

    myCache.get('someItem'); // undefined

}, 15000); // 15 seconds

See Cache#put

Remove items

myCache.put('someItem', { name: 'John Doe' });

myCache.remove('someItem');

myCache.get('someItem'); // undefined

See Cache#remove

Clear all items

myCache.put('someItem', { name: 'John Doe' });
myCache.put('someOtherItem', { name: 'Sally Jean' });

myCache.removeAll();

myCache.get('someItem'); // undefined
myCache.get('someOtherItem'); // undefined

See Cache#removeAll

Destroy a cache

myCache.destroy();

myCache.get('someItem'); // Will throw an error - Don't try to use a cache after destroying it!

$angularCacheFactory.get('myCache'); // undefined

See Cache#destory

Get info about a cache

myCache.info(); // { id: 'myCache', size: 13 }

See Cache#info

Roadmap

0.8.x Beta
  • AngularCache.keySet()
  • AngularCache.keys()
  • AngularCache.setOptions()
  • Bug fixes
  • Submit project to Angular.js user groups for feedback again.
0.9.x Release Candidate
  • Bug fixes
  • Documentation tidy up.
1.0.0 Stable Release
  • Yay!

Contributing

Submitting Issues

  1. Make sure you aren't submitting a duplicate issue.
  2. Carefully describe how to reproduce the problem.
  3. Expect prompt feedback.

Submitting Pull Requests

  1. Fork
  2. For hotfixes branch from master, otherwise from develop. Prefix name of branch with issue label. E.g. hotfix-missing-semicolon, feature-my-feature, etc.
  3. Make sure grunt build passes with zero warnings/errors.
  4. Make sure your code follows the style guidelines.
    • This project uses 4-space indentation and single-quotes.
  5. Make sure your pull request references/closes the proper issues.
  6. For hotfixes submit request to be merged into master, otherwise into develop.

License

MIT License

Copyright (C) 2013 Jason Dobry

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

angular-cache improves upon the capabilities of the $cacheFactory provided by AngularJS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%