datasource-cache-debug.js revision 76ca635d61eb3f9fb7c9d788a44fa8b1690aa138
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Plugs DataSource with caching functionality.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @module datasource
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @submodule datasource-cache
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * DataSourceCache extension binds Cache to DataSource.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @class DataSourceCacheExtension
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glassvar DataSourceCacheExtension = function() {
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The namespace for the plugin. This will be the property on the host which
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * references the plugin instance.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property NS
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @value "cache"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Class name.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property NAME
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @value "dataSourceCacheExtension"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Internal init() handler.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method initializer
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param config {Object} Config object.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.doBefore("_defRequestFn", this._beforeDefRequestFn);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.doBefore("_defResponseFn", this._beforeDefResponseFn);
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * First look for cached response, then send request to live data.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _beforeDefRequestFn
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param e {Event.Facade} Event Facade with the following properties:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>request (Object)</dt> <dd>The request.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>callback (Object)</dt> <dd>The callback object.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Is response already in the Cache?
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass this.get("host").fire("response", Y.mix(entry, e));
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass return new Y.Do.Halt("DataSourceCache extension halted _defRequestFn");
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Adds data to cache before returning data.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @method _beforeDefResponseFn
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @param e {Event.Facade} Event Facade with the following properties:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>request (Object)</dt> <dd>The request.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>success (Function)</dt> <dd>Success handler.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>data (Object)</dt> <dd>Raw data.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>response (Object)</dt> <dd>Normalized response object with the following properties:
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>cached (Object)</dt> <dd>True when response is cached.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>results (Object)</dt> <dd>Parsed results.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>error (Object)</dt> <dd>Error object.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @protected
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass // Add to Cache before returning
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.namespace("Plugin").DataSourceCacheExtension = DataSourceCacheExtension;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * DataSource plugin adds cache functionality.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @class DataSourceCache
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @extends Cache
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @uses Plugin.Base, DataSourceCachePlugin
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass var cache = config && config.cache ? config.cache : Y.Cache,
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass tmpclass = Y.Base.create("dataSourceCache", cache, [Y.Plugin.Base, Y.Plugin.DataSourceCacheExtension]),
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * The namespace for the plugin. This will be the property on the host which
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * references the plugin instance.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property NS
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @value "cache"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * Class name.
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @property NAME
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @type String
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass * @value "dataSourceCache"
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav GlassY.namespace("Plugin").DataSourceCache = DataSourceCache;
76ca635d61eb3f9fb7c9d788a44fa8b1690aa138Dav Glass}, '@VERSION@' ,{requires:['datasource-local', 'cache-base', 'plugin']});