A simple caching layer on the browser's localStorage
## Usage
### Creation
Create a Burry `Store`, optionally passing a namespace. A default store is always available with no namespace:
```javascript
varburry=newBurry.Store('mystuff');
```
If you want to also set a default time-to-live on a namespaced store, pass the time-to-live as a second parameter. For instance,
```javascript
varburrywithttl=newBurry.Store('mystuff',10);
```
will create a store where the default time-to-live when you set items is 10 minutes.
You can obtain all available stores, by invoking `stores()`:
```javascript
varstores=Burry.stores();// stores is ['', 'mystuff']
```
### Getting/Setting
`set` and `get` JSON-serializable javascript objects easily to and from the cache.
```javascript
burry.set('foo',{bar:'burry'});
varfoo=burry.get('foo');// foo is {bar: 'burry'}
foo=burry.get('unknown');// foo is undefined
```
You can specify a time-to-live per key/value. This is expressed in minutes:
```javascript
burry.set('foo',{bar:'burry'},10);
varfoo=burry.get('foo');// foo is {bar: 'burry'}
...
// Ten minutes later...
foo=burry.get('foo');// foo is undefined and also removed from localStorage
```
Attempting to `set` when the `localStorage` is full, will try again after flushing expired key/values from the cache. If this does not succeed either, your `set` will be ignored.
### Counters
You can increment/decrement persistent counters. If the counter does not exist, it is initialized with the value 0.
```javascript
burry.incr('counter');
burry.incr('counter');
varcounter=burry.get('counter');// counter === 2
burry.decr('counter');
counter=burry.get('counter');// counter === 1
```
### Helpers
The following more esoteric functions are also exposed:
*`burry.add(key, value, ttl)`, same as `set` except it will only add the key if it does not already exist, or it has already expired.
*`burry.replace(key, value, ttl)`, same as `set` except it will only add the key if it does already exist and has not expired.
*`burry.flush()`, removes from `localStorage` all Burry items.
*`burry.flushExpired()`, removes from `localStorage` all expired Burry items of the store.
*`Burry.flushExpired()`, removes from `localStorage` all expired Burry items of all stores.
*`burry.keys()`, returns all stored keys.
*`burry.expirableKeys()` return an dictionary of key/values where the values are the TTL of the keys from Epoch.
*`burry.hasExpired(key)`, returns whether a key has expired.
*`Burry.isSupported()`, returns whether `localStorage` and `JSON` serialization are supported on the browser.
## License
Backbone.xmpp.storage is Copyright (C) 2012 Yiorgis Gozadinos, Riot AS.
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
*
* @namespace
*/
varjasmine={};
if(isCommonJS)exports.jasmine=jasmine;
/**
* @private
*/
jasmine.unimplementedMethod_=function(){
thrownewError("unimplemented method");
};
/**
* Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
* a plain old variable and may be redefined by somebody else.
*
* @private
*/
jasmine.undefined=jasmine.___undefined___;
/**
* Show diagnostic messages in the console if set to true
*
*/
jasmine.VERBOSE=false;
/**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
*
*/
jasmine.DEFAULT_UPDATE_INTERVAL=250;
/**
* Default timeout interval in milliseconds for waitsFor() blocks.
*/
jasmine.DEFAULT_TIMEOUT_INTERVAL=5000;
jasmine.getGlobal=function(){
functiongetGlobal(){
returnthis;
}
returngetGlobal();
};
/**
* Allows for bound functions to be compared. Internal use only.
*
* @ignore
* @private
* @param base {Object} bound 'this' for the function
mismatchValues.push("'"+property+"' was '"+(b[property]?jasmine.util.htmlEscape(b[property].toString()):b[property])+"' in expected, but was '"+(a[property]?jasmine.util.htmlEscape(a[property].toString()):a[property])+"' in actual.");
thrownewError('Expected a spy, but got '+jasmine.pp(this.actual)+'.');
}
this.message=function(){
if(this.actual.callCount===0){
// todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw]
return[
"Expected spy "+this.actual.identity+" to have been called with "+jasmine.pp(expectedArgs)+" but it was never called.",
"Expected spy "+this.actual.identity+" not to have been called with "+jasmine.pp(expectedArgs)+" but it was."
];
}else{
return[
"Expected spy "+this.actual.identity+" to have been called with "+jasmine.pp(expectedArgs)+" but was called with "+jasmine.pp(this.actual.argsForCall),
"Expected spy "+this.actual.identity+" not to have been called with "+jasmine.pp(expectedArgs)+" but was called with "+jasmine.pp(this.actual.argsForCall)
mismatchValues.push("'"+property+"' was '"+(other[property]?jasmine.util.htmlEscape(other[property].toString()):other[property])+"' in expected, but was '"+(this.sample[property]?jasmine.util.htmlEscape(this.sample[property].toString()):this.sample[property])+"' in actual.");