src/cache.js

Private method clean

Returns an Undefined
(undefined)

clean : function () { return utility.iterate( cache.items, function ( v, k ) { if ( cache.expired( k ) ) { cache.expire( k, true ); } }); },

Private method expire

Expires a URI from the local cache Events: expire Fires when the URI expires

Parameters:

  • uri must be a String.
    (URI of the local representation)

  • silent must be a Boolean.
    ([Optional] If 'true', the event will not fire)

Returns an Undefined
(undefined)

expire : function ( uri, silent ) { silent = ( silent === true ); if ( cache.items[uri] !== undefined ) { delete cache.items[uri]; if ( !silent ) { observer.fire( uri, "beforeExpire, expire, afterExpire" ); } return true; } else { return false; } },

Private method expired

Determines if a URI has expired

Parameters:

  • uri must be an Object.
    (Cached URI object)

Returns a Boolean
(True if the URI has expired)

expired : function ( uri ) { var item = cache.items[uri]; return item !== undefined && item.expires !== undefined && item.expires < new Date(); },

Private method get

Returns the cached object {headers, response} of the URI or false

Parameters:

  • uri must be a String.
    (URI/Identifier for the resource to retrieve from cache)

  • expire must be a Boolean.
    ([Optional] If 'false' the URI will not expire)

  • silent must be a Boolean.
    ([Optional] If 'true', the event will not fire)

Returns a Mixed
(URI Object {headers, response} or False)

get : function ( uri, expire ) { uri = utility.parse( uri ).href; expire = ( expire !== false ); if ( cache.items[uri] === undefined ) { return false; } if ( expire && cache.expired( uri ) ) { cache.expire( uri ); return false; } return utility.clone( cache.items[uri], true ); },

Private method set

Sets, or updates an item in cache.items

Parameters:

  • uri must be a String.
    (URI to set or update)

  • property must be a String.
    (Property of the cached URI to set)

  • value can be of any type.
    (Value to set)

Returns a Mixed
(URI Object {headers, response} or undefined)

set : function ( uri, property, value ) { uri = utility.parse( uri ).href; if ( cache.items[uri] === undefined ) { cache.items[uri] = {}; cache.items[uri].permission = 0; } if ( property === "permission" ) { cache.items[uri].permission |= value; } else if ( property === "!permission" ) { cache.items[uri].permission &= ~value; } else { cache.items[uri][property] = value; } return cache.items[uri]; } };