Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
Added Grunt.js build and updated README.md
  • Loading branch information
jmdobry committed May 19, 2013
1 parent 467b641 commit 57180a8
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 226 deletions.
18 changes: 5 additions & 13 deletions .gitignore
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
46 changes: 46 additions & 0 deletions Gruntfile.js
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']);
};
134 changes: 130 additions & 4 deletions README.md
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)
68 changes: 35 additions & 33 deletions ngAdvancedCache-0.3.1.js → dist/ngAdvancedCache-0.4.0.js
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>
*
Expand All @@ -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', []);

Expand All @@ -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() {

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions dist/ngAdvancedCache-0.4.0.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions docs/$AdvancedCacheFactoryProvider.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h4 class="name" id="$AdvancedCacheFactoryProvider"><span class="type-signature"

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ngAdvancedCache-0.3.1.js.html">ngAdvancedCache-0.3.1.js</a>, <a href="ngAdvancedCache-0.3.1.js.html#line42">line 42</a>
<a href="ngAdvancedCache-0.4.0.js.html">ngAdvancedCache-0.4.0.js</a>, <a href="ngAdvancedCache-0.4.0.js.html#line43">line 43</a>
</li></ul></dd>


Expand Down Expand Up @@ -112,21 +112,22 @@ <h4 class="name" id="$AdvancedCacheFactoryProvider"><span class="type-signature"

<h5>Example</h5>

<pre class="prettyprint"><code> angular.module('myModule').service('myService', ['$advancedCacheFactory', function ($advancedCacheFactory) {
<pre class="prettyprint"><code> 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
var myLRUCache = $advancedCacheFactory('myLRUCache', {
capacity: 10
});

// create an LRU cache with a capacity of 10
advancedCache = $advancedCacheFactory({
capacity: 10
});

// create a cache whose items have a default maximum lifetime of 10 minutes
advancedCache = $advancedCacheFactory({
maxAge: 600000
});
}</code></pre>
// create a cache whose items have a default maximum lifetime of 10 minutes
var myTimeLimitedCache = $advancedCacheFactory('myTimeLimitedCache', {
maxAge: 600000
});
}
]);</code></pre>


</dd>
Expand Down Expand Up @@ -167,7 +168,7 @@ <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-n
<br clear="both">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Sun May 19 2013 01:42:29 GMT-0600 (MDT)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Sun May 19 2013 14:59:59 GMT-0600 (MDT)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit 57180a8

Please sign in to comment.