Permalink
Browse files

fire also ttl expired keys

  • Loading branch information...
1 parent 6b4f87b commit 72c44323d33bb6a4c3610bdb774184e3a43a230f Andris Reinman committed Aug 23, 2012
Showing with 18 additions and 13 deletions.
  1. +7 −2 jstorage.js
  2. +11 −11 jstorage.min.js
View
@@ -27,7 +27,7 @@
(function(){
var
/* jStorage version */
- JSTORAGE_VERSION = "0.2.1",
+ JSTORAGE_VERSION = "0.2.2",
/* detect a dollar object or create one if not found */
$ = window.jQuery || window.$ || (window.$ = {}),
@@ -442,7 +442,7 @@
* Removes expired keys
*/
function _handleTTL(){
- var curtime, i, TTL, nextExpire = Infinity, changed = false;
+ var curtime, i, TTL, CRC32, nextExpire = Infinity, changed = false, deleted = [];
clearTimeout(_ttl_timeout);
@@ -453,12 +453,15 @@
curtime = +new Date();
TTL = _storage.__jstorage_meta.TTL;
+ CRC32 = _storage.__jstorage_meta.CRC32;
for(i in TTL){
if(TTL.hasOwnProperty(i)){
if(TTL[i] <= curtime){
delete TTL[i];
+ delete CRC32[i];
delete _storage[i];
changed = true;
+ deleted.push(i);
}else if(TTL[i] < nextExpire){
nextExpire = TTL[i];
}
@@ -473,6 +476,8 @@
// save changes
if(changed){
_save();
+ _publishChange();
+ _fireObservers(deleted, "deleted");
}
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 72c4432

Please sign in to comment.