2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
8
8
YUI.add('datasource-cache', function(Y) {
11
* Extends DataSource with caching functionality.
11
* Plugs DataSource with caching functionality.
13
13
* @module datasource
14
14
* @submodule datasource-cache
18
* Adds cacheability to the DataSource Utility.
19
* @class DataSourceCache
22
var DataSourceCache = function() {
23
DataSourceCache.superclass.constructor.apply(this, arguments);
18
* DataSourceCache extension binds Cache to DataSource.
19
* @class DataSourceCacheExtension
21
var DataSourceCacheExtension = function() {
26
Y.mix(DataSourceCache, {
24
Y.mix(DataSourceCacheExtension, {
28
26
* The namespace for the plugin. This will be the property on the host which
29
27
* references the plugin instance.
46
* @value "dataSourceCache"
44
* @value "dataSourceCacheExtension"
48
NAME: "dataSourceCache",
50
/////////////////////////////////////////////////////////////////////////////
52
// DataSourceCache Attributes
54
/////////////////////////////////////////////////////////////////////////////
46
NAME: "dataSourceCacheExtension"
61
Y.extend(DataSourceCache, Y.Cache, {
49
DataSourceCacheExtension.prototype = {
63
51
* Internal init() handler.
88
76
// Is response already in the Cache?
89
77
var entry = (this.retrieve(e.request)) || null;
90
78
if(entry && entry.response) {
91
this.get("host").fire("response", Y.mix({response: entry.response}, e));
92
return new Y.Do.Halt("DataSourceCache plugin halted _defRequestFn");
79
this.get("host").fire("response", Y.mix(entry, e));
80
return new Y.Do.Halt("DataSourceCache extension halted _defRequestFn");
97
85
* Adds data to cache before returning data.
123
111
_beforeDefResponseFn: function(e) {
124
112
// Add to Cache before returning
125
if(e.response && !e.response.cached) {
126
e.response.cached = true;
127
this.add(e.request, e.response, (e.callback && e.callback.argument));
113
if(e.response && !e.cached) {
114
this.add(e.request, e.response);
119
Y.namespace("Plugin").DataSourceCacheExtension = DataSourceCacheExtension;
124
* DataSource plugin adds cache functionality.
125
* @class DataSourceCache
127
* @uses Plugin.Base, DataSourceCachePlugin
129
function DataSourceCache(config) {
130
var cache = config && config.cache ? config.cache : Y.Cache,
131
tmpclass = Y.Base.create("dataSourceCache", cache, [Y.Plugin.Base, Y.Plugin.DataSourceCacheExtension]),
132
tmpinstance = new tmpclass(config);
133
tmpclass.NS = "tmpClass";
137
Y.mix(DataSourceCache, {
139
* The namespace for the plugin. This will be the property on the host which
140
* references the plugin instance.
157
* @value "dataSourceCache"
159
NAME: "dataSourceCache"
132
Y.namespace('Plugin').DataSourceCache = DataSourceCache;
135
}, '3.1.1' ,{requires:['datasource-local', 'cache']});
163
Y.namespace("Plugin").DataSourceCache = DataSourceCache;
167
}, '3.2.0' ,{requires:['datasource-local']});