-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Grunt.js build and updated README.md
- Loading branch information
Showing
13 changed files
with
348 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules/ | ||
npm-debug.log | ||
|
||
# IntelliJ IDEA | ||
.idea | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* ngAdvancedCache | ||
* http://github.com/jmdobry/ngAdvancedCache | ||
* | ||
* Copyright (c) 2013 Jason Dobry <http://jmdobry.github.io/ngAdvancedCache> | ||
* Licensed under the MIT license. <https://github.com/jmdobry/ngAdvancedCache/blob/master/LICENSE> | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
clean: ['dist/'], | ||
jshint: ['src/ngAdvancedCache.js'], | ||
copy: { | ||
options: { | ||
processContent: function (contents) { | ||
contents = contents.replace(/<%= pkg.version %>/g, grunt.file.readJSON('package.json').version); | ||
return contents; | ||
} | ||
}, | ||
dist: { | ||
src: ['src/ngAdvancedCache.js'], | ||
dest: 'dist/ngAdvancedCache-<%= pkg.version %>.js' | ||
} | ||
}, | ||
uglify: { | ||
main: { | ||
files: { | ||
'dist/ngAdvancedCache-<%= pkg.version %>.min.js': ['dist/ngAdvancedCache-<%= pkg.version %>.js'] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
// These plugins provide necessary tasks. | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
|
||
grunt.registerTask('build', ['clean', 'jshint', 'copy', 'uglify']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,136 @@ | ||
ngAdvancedCache | ||
=============== | ||
##### ngAdvancedCache is a caching system that improves upon the capabilities of the $cacheFactory provided by AngularJS. | ||
|
||
ngAdvancedCache is a caching system that improves upon the capabilities of the $cacheFactory provided by AngularJS. | ||
## Table of Contents | ||
- [Features](#features) | ||
- [Download](#download) | ||
- [Usage](#usage) | ||
- [License](#license) | ||
|
||
## Documentation | ||
[JsDocs](http://jmdobry.github.io/ngAdvancedCache/docs/) | ||
## Features | ||
##### Capacity | ||
Set maximum capacity on a cache, turning it into an LRU cache. | ||
##### MaxAge | ||
Set a default maximum lifetime on all items in a cache. This uses a lazy check. When an item is requested it is checked for expiration. If the item has expired it is removed from the cache and the request results in a miss. | ||
|
||
## Download | ||
| Type | File | Size | | ||
| ------------- | ----------------------------------------------------------------------------------------------------------------------- | ----- | | ||
| Production | [ngAdvancedCache-0.4.0.min.js](https://raw.github.com/jmdobry/ngAdvancedCache/master/dist/ngAdvancedCache-0.4.0.min.js) | 1.3 KB | | ||
| Development | [ngAdvancedCache-0.4.0.js](https://raw.github.com/jmdobry/ngAdvancedCache/master/dist/ngAdvancedCache-0.4.0.js) | 15.4 KB | | ||
|
||
## Usage | ||
|
||
- [Create a cache](#create-a-cache) | ||
- [Retrieve items](#retrieve-items) | ||
- [Add items](#add-items) | ||
- [Remove items](#remove-items) | ||
- [Clear all items](#clear-all-items) | ||
- [Get info about a cache](#get-info-about-a-cache) | ||
- [API Documentation](http://jmdobry.github.io/ngAdvancedCache/docs/) | ||
|
||
##### Create a cache | ||
```javascript | ||
angular.module('myApp', ['ngAdvancedCache']); | ||
|
||
angular.module('myApp').service('myService', ['$advancedCacheFactory', | ||
function ($advancedCacheFactory) { | ||
|
||
// create a cache with default settings | ||
var myCache = $advancedCacheFactory('myCache'); | ||
|
||
// create an LRU cache with a capacity of 10 | ||
var myLRUCache = $advancedCacheFactory('myLRUCache', { | ||
capacity: 10 | ||
}); | ||
|
||
// create a cache whose items have a default maximum lifetime of 10 minutes | ||
var myTimeLimitedCache = $advancedCacheFactory('myTimeLimitedCache', { | ||
maxAge: 600000 | ||
}); | ||
} | ||
]); | ||
``` | ||
|
||
##### Retrieve items | ||
```javascript | ||
angular.module('myApp').service('myOtherService', ['$advancedCacheFactory', | ||
function ($advancedCacheFactory) { | ||
|
||
var myCache = $advancedCacheFactory.get('myCache'); | ||
} | ||
]); | ||
``` | ||
|
||
##### Add items | ||
```javascript | ||
myCache.put('someItem', { name: 'John Doe' }); | ||
|
||
myCache.get('someItem'); // { name: 'John Doe' }); | ||
``` | ||
|
||
Give a specific item a maximum age | ||
```javascript | ||
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 | ||
``` | ||
|
||
##### Remove items | ||
```javascript | ||
myCache.put('someItem', { name: 'John Doe' }); | ||
|
||
myCache.remove('someItem'); | ||
|
||
myCache.get('someItem'); // undefined | ||
``` | ||
|
||
##### Clear all items | ||
```javascript | ||
myCache.put('someItem', { name: 'John Doe' }); | ||
myCache.put('someOtherItem', { name: 'Sally Jean' }); | ||
|
||
myCache.removeAll(); | ||
|
||
myCache.get('someItem'); // undefined | ||
myCache.get('someOtherItem'); // undefined | ||
``` | ||
|
||
##### Get info about a cache | ||
```javascript | ||
myCache.info(); // { id: 'myCache', size: 13 } | ||
``` | ||
|
||
##### [API Documentation](http://jmdobry.github.io/ngAdvancedCache/docs/) | ||
|
||
## License | ||
[MIT](https://github.com/jmdobry/ngAdvancedCache/blob/master/LICENSE) | ||
[MIT License](https://github.com/jmdobry/ngAdvancedCache/blob/master/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. | ||
|
||
[features](#features) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* @author Jason Dobry <[email protected]> | ||
* @file ngAdvancedCache-0.3.1.js | ||
* @version 0.3.1 | ||
* @file ngAdvancedCache-0.4.0.js | ||
* @version 0.4.0 | ||
* @copyright (c) 2013 Jason Dobry <http://jmdobry.github.io/ngAdvancedCache> | ||
* @license MIT <https://github.com/jmdobry/ngAdvancedCache/blob/master/LICENSE> | ||
* | ||
|
@@ -19,23 +19,24 @@ | |
* functionality. | ||
* | ||
* @example | ||
angular.module('myApp', ['ngAdvancedCache']); | ||
angular.module('myApp', ['ngAdvancedCache']); | ||
angular.module('myApp').service('myService', ['$advancedCacheFactory', function ($advancedCacheFactory) { | ||
angular.module('myApp').service('myService', ['$advancedCacheFactory', | ||
function ($advancedCacheFactory) { | ||
// create a cache with default settings | ||
var myCache = $advancedCacheFactory('myCache'); | ||
// create a cache with default settings | ||
var advancedCache = $advancedCacheFactory(); | ||
// create an LRU cache with a capacity of 10 | ||
advancedCache = $advancedCacheFactory({ | ||
capacity: 10 | ||
}); | ||
// create an LRU cache with a capacity of 10 | ||
var myLRUCache = $advancedCacheFactory('myLRUCache', { | ||
capacity: 10 | ||
}); | ||
// create a cache whose items have a default maximum lifetime of 10 minutes | ||
advancedCache = $advancedCacheFactory({ | ||
maxAge: 600000 | ||
}); | ||
} | ||
// create a cache whose items have a default maximum lifetime of 10 minutes | ||
var myTimeLimitedCache = $advancedCacheFactory('myTimeLimitedCache', { | ||
maxAge: 600000 | ||
}); | ||
} | ||
]); | ||
*/ | ||
angular.module('ngAdvancedCache', []); | ||
|
||
|
@@ -45,21 +46,22 @@ | |
* @see {@link http://docs.angularjs.org/api/ng.$cacheFactory|ng.$cacheFactory} | ||
* | ||
* @example | ||
angular.module('myModule').service('myService', ['$advancedCacheFactory', function ($advancedCacheFactory) { | ||
// create a cache with default settings | ||
var advancedCache = $advancedCacheFactory(); | ||
// create an LRU cache with a capacity of 10 | ||
advancedCache = $advancedCacheFactory({ | ||
capacity: 10 | ||
}); | ||
angular.module('myApp').service('myService', ['$advancedCacheFactory', | ||
function ($advancedCacheFactory) { | ||
// create a cache with default settings | ||
var myCache = $advancedCacheFactory('myCache'); | ||
// create an LRU cache with a capacity of 10 | ||
var myLRUCache = $advancedCacheFactory('myLRUCache', { | ||
capacity: 10 | ||
}); | ||
// create a cache whose items have a default maximum lifetime of 10 minutes | ||
advancedCache = $advancedCacheFactory({ | ||
maxAge: 600000 | ||
}); | ||
} | ||
// create a cache whose items have a default maximum lifetime of 10 minutes | ||
var myTimeLimitedCache = $advancedCacheFactory('myTimeLimitedCache', { | ||
maxAge: 600000 | ||
}); | ||
} | ||
]); | ||
*/ | ||
function $AdvancedCacheFactoryProvider() { | ||
|
||
|
@@ -80,10 +82,10 @@ | |
var myCache = $advancedCacheFactory('myCache'); | ||
// create an LRU cache with a capacity of 10 | ||
var myCapacityCache = $advancedCacheFactory('myCapacityCache', { capacity: 10 }); | ||
var myLRUCache = $advancedCacheFactory('myLRUCache', { capacity: 10 }); | ||
// create a cache whose items have a default maximum lifetime of 10 minutes | ||
var myMaxAgeCache = $advancedCacheFactory('myMaxAgeCache', { maxAge: 600000 }); | ||
var myTimeLimitedCache = $advancedCacheFactory('myTimeLimitedCache', { maxAge: 600000 }); | ||
}); | ||
*/ | ||
function AdvancedCache(cacheId, options) { | ||
|
@@ -344,7 +346,7 @@ | |
*/ | ||
function advancedCacheFactory(cacheId, options) { | ||
if (cacheId in caches) { | ||
throw Error('cacheId ' + cacheId + ' taken'); | ||
throw new Error('cacheId ' + cacheId + ' taken'); | ||
} | ||
|
||
caches[cacheId] = new AdvancedCache(cacheId, options); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.