datasource-cache.js revision 9e58396d3563168e91dc995170288bc18b84ab6f
/**
* Extends DataSource with caching functionality.
*
* @module datasource-cache
* @requires datasource-base,cache
* @title DataSource Cache Extension
*/
var BASE = Y.DataSource,
/**
* Adds cacheability to the YUI DataSource utility.
* @class Cacheable
*/
Cacheable = function() {};
/////////////////////////////////////////////////////////////////////////////
//
// DataSource Attributes
//
/////////////////////////////////////////////////////////////////////////////
/**
* Instance of Y.Cache. Caching is useful to reduce the number of server
* connections. Recommended only for data sources that return comprehensive
* results for queries or when stale data is not an issue.
*
* @attribute cache
* @type Y.Cache
* @default null
*/
cache: {
value: null,
},
//TODO: Cleanup for destroy()?
}
}
};
/**
* First look for cached response, then send request to live data.
*
* @method _beforeRequest
* @param e {Event.Facade} Event Facade.
* @param o {Object} Object with the following properties:
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object.</dd>
* </dl>
* @protected
*/
_beforeRequest: function(e, o) {
// Is response already in the Cache?
//BASE.issueCallback(entry.response);
//return new Y.Do.Halt("msg", "newRetVal");
}
},
/**
* Adds data to cache before returning data.
*
* @method _beforeResponse
* @param e {Event.Facade} Event Facade.
* @param o {Object} Object with the following properties:
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object.</dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* <dt>results (Object)</dt> <dd>Parsed results.</dd>
* <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
* </dl>
* @protected
*/
_beforeResponse: function(e, o) {
// Add to Cache before returning
if(this.get("cache")) {
}
}
};
dynamic: false
});