cache-debug.js revision 337ff934a4b8722dd253d7afe73bf29a52d34dd9
* cache and retrieve data from a local JavaScript struct. * Base class for the YUI Cache utility. ///////////////////////////////////////////////////////////////////////////// // Cache static properties ///////////////////////////////////////////////////////////////////////////// * The namespace for the plugin. This will be the property on the host which * references the plugin instance. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// * @description Maximum number of entries the Cache can hold. * Set to 0 to turn off caching. // If the cache is full, make room by removing stalest element (index=0) * @description Number of entries currently cached. * @description Cached entries. ///////////////////////////////////////////////////////////////////////////// // Cache private properties ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// * @description Internal init() handler. * @param config {Object} Config object. * @description Fired when an entry is added. * @param e {Event.Facade} Event Facade with the following properties: * <dt>entry (Object)</dt> <dd>The cached entry.</dd> * @description Fired when the cache is flushed. * @param e {Event.Facade} Event Facade object. * @preventable _defFlushFn * @description Fired when an entry is requested from the cache. * @param e {Event.Facade} Event Facade with the following properties: * <dt>request (Object)</dt> <dd>The request object.</dd> * @description Fired when an entry is retrieved from the cache. * @param e {Event.Facade} Event Facade with the following properties: * <dt>entry (Object)</dt> <dd>The retrieved entry.</dd> // Initialize internal values Y.
log(
"Cache initialized",
"info",
"cache");
* @description Internal destroy() handler. Y.
log(
"Cache destroyed",
"info",
"cache");
///////////////////////////////////////////////////////////////////////////// // Cache protected methods ///////////////////////////////////////////////////////////////////////////// * @param e {Event.Facade} Event Facade with the following properties: * <dt>entry (Object)</dt> <dd>The cached entry.</dd> // If the cache at or over capacity, make room by removing stalest element (index=0) // Add entry to cache in the newest position, at the end of the array * @param e {Event.Facade} Event Facade object. Y.
log(
"Cache flushed",
"info",
"cache");
* Default overridable method compares current request with given cache entry. * Returns true if current request matches the cached request, otherwise * false. Implementers should override this method to customize the * cache-matching algorithm. * @param request {Object} Request object. * @param entry {Object} Cached entry. * @return {Boolean} True if current request matches given cached request, false otherwise. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// * Adds a new entry to the cache of the format * {request:request, response:response, payload:payload}. * If cache is full, evicts the stalest entry before adding the new one. * @param request {Object} Request object. * @param response {Object} Response object. * @param payload {Object} (optional) Arbitrary data payload. * Retrieves cached entry for given request, if available, and refreshes * entry in the cache. Returns null if there is no cache match. * @param request {Object} Request object. * @return {Object} Cached entry object with the properties request, response, and payload, or null. // If cache is enabled... // Loop through each cached entry starting from the newest // Execute matching function // Refresh the position of the cache hit // Remove element from its original location