Skip to content

Commit

Permalink
Fixes #1.
Browse files Browse the repository at this point in the history
Fixes #2.

Stable Version 1.2.0
  • Loading branch information
jmdobry committed Oct 12, 2015
1 parent c566331 commit 0361ba4
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 59 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
##### 1.2.0 - 12 July 2015

###### Backwards compatible API changes
- #2 - Specify MaxAge on put

###### Bug fixes
- #1 - After reinitializing a cache from localStorage, info().size returns 0

##### 1.1.0 - 10 July 2015

Upgraded dependencies
Expand Down
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ module.exports = function (grunt) {
'test/**/*.js'
]
}
},
c9: {
browsers: ['PhantomJS'],
options: {
files: [
'node_modules/es6-promise/dist/es6-promise.js',
'dist/cachefactory.min.js',
'./karma.start.js',
'test/**/*.js'
]
}
}
},
coveralls: {
Expand All @@ -111,6 +122,7 @@ module.exports = function (grunt) {
});

grunt.registerTask('test', ['build', 'karma:dist', 'karma:min']);
grunt.registerTask('test_c9', ['build', 'karma:c9']);
grunt.registerTask('build', [
'clean',
'webpack',
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ CacheFactory is a very simple and useful cache.

__Latest Release:__ [![Latest Release](https://img.shields.io/github/release/jmdobry/cachefactory.svg?style=flat-square)](https://github.com/jmdobry/cachefactory/releases)

__Status:__

[![Dependency Status](https://img.shields.io/gemnasium/jmdobry/cachefactory.svg?style=flat-square)](https://gemnasium.com/jmdobry/cachefactory) [![Coverage Status](https://img.shields.io/coveralls/jmdobry/cachefactory/master.svg?style=flat-square)](https://coveralls.io/r/jmdobry/cachefactory?branch=master) [![Codacity](https://img.shields.io/codacy/5e27e21d0c4c4d4cb203d589384aa93a.svg?style=flat-square)](https://www.codacy.com/public/jasondobry/cachefactory/dashboard)

__Supported Browsers:__

[![browsers](https://img.shields.io/badge/Browser-Chrome%2CFirefox%2CSafari%2COpera%2CIE%209%2B%2CiOS%20Safari%207.1%2B%2CAndroid%20Browser%202.3%2B-green.svg?style=flat-square)](https://github.com/jmdobry/cachefactory)

### Table of Contents
- [Quick Start](#quick-start)
- [The Basics](#the-basics)
Expand Down Expand Up @@ -195,6 +187,12 @@ Will be passed a third `done` argument if the cache is in `passive` mode. This a

The number of milliseconds until a newly inserted item expires. Default: `Number.MAX_VALUE`.

You can also specify a `maxAge` for an individual item like so:

```js
myCache.put('foo', 'bar', { maxAge: 60000 });
```

##### `recycleFreq`

Determines how often a cache will scan for expired items when in `aggressive` mode. Default: `1000` (milliseconds).
Expand Down
36 changes: 19 additions & 17 deletions dist/cachefactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* cachefactory
* @version 1.1.0 - Homepage <http://jmdobry.github.io/cachefactory/>
* @version 1.2.0 - Homepage <http://jmdobry.github.io/cachefactory/>
* @author Jason Dobry <jason.dobry@gmail.com>
* @copyright (c) 2013-2015 Jason Dobry
* @license MIT <https://github.com/jmdobry/cachefactory/blob/master/LICENSE>
Expand All @@ -11,7 +11,7 @@
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(factory);
define([], factory);
else if(typeof exports === 'object')
exports["CacheFactory"] = factory();
else
Expand Down Expand Up @@ -299,7 +299,7 @@ return /******/ (function(modules) { // webpackBootstrap
created: item.created,
accessed: item.accessed,
expires: item.expires,
isExpired: new Date().getTime() - item.created > this.$$maxAge
isExpired: new Date().getTime() - item.created > (item.maxAge || this.$$maxAge)
};
} else {
return undefined;
Expand All @@ -312,7 +312,7 @@ return /******/ (function(modules) { // webpackBootstrap
created: item.created,
accessed: item.accessed,
expires: item.expires,
isExpired: new Date().getTime() - item.created > this.$$maxAge
isExpired: new Date().getTime() - item.created > (item.maxAge || this.$$maxAge)
};
} else {
return undefined;
Expand Down Expand Up @@ -415,7 +415,11 @@ return /******/ (function(modules) { // webpackBootstrap
accessed: now
};

item.expires = item.created + this.$$maxAge;
if (options.maxAge) {
item.maxAge = options.maxAge;
}

item.expires = item.created + (item.maxAge || this.$$maxAge);

if ($$storage) {
if (_isPromiseLike(item.value)) {
Expand Down Expand Up @@ -651,7 +655,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.$$maxAge === Number.MAX_VALUE) {
item.expires = Number.MAX_VALUE;
} else {
item.expires = item.created + this.$$maxAge;
item.expires = item.created + (item.maxAge || this.$$maxAge);
}
$$expiresHeap.push({
key: key,
Expand All @@ -667,7 +671,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.$$maxAge === Number.MAX_VALUE) {
$$data[key].expires = Number.MAX_VALUE;
} else {
$$data[key].expires = $$data[key].created + this.$$maxAge;
$$data[key].expires = $$data[key].created + ($$data[key].maxAge || this.$$maxAge);
}
$$expiresHeap.push($$data[key]);
}
Expand Down Expand Up @@ -797,18 +801,16 @@ return /******/ (function(modules) { // webpackBootstrap
var shouldReInsert = false;
var items = {};

if (typeof this.$$storageMode === 'string' && this.$$storageMode !== storageMode) {
var keys = this.keys();
var keys = this.keys();

if (keys.length) {
for (var i = 0; i < keys.length; i++) {
items[keys[i]] = this.get(keys[i]);
}
for (i = 0; i < keys.length; i++) {
this.remove(keys[i]);
}
shouldReInsert = true;
if (keys.length) {
for (var i = 0; i < keys.length; i++) {
items[keys[i]] = this.get(keys[i]);
}
for (i = 0; i < keys.length; i++) {
this.remove(keys[i]);
}
shouldReInsert = true;
}

this.$$storageMode = storageMode;
Expand Down
Loading

1 comment on commit 0361ba4

@sloops77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jmdobry,

im surprised you fixed #1 like this because it resets the saved timestamps in the lruheap by calling this.get

Please sign in to comment.