~landscape/lazr-js/production

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/datasource/datasource-cache-debug.js

  • Committer: Sidnei da Silva
  • Date: 2010-09-18 14:54:13 UTC
  • mfrom: (166.11.12 toolchain)
  • Revision ID: sidnei.da.silva@canonical.com-20100918145413-8scojue3rodcm0f4
- Merge from lazr-js trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
version: 3.1.1
6
 
build: 47
 
5
version: 3.2.0
 
6
build: 2676
7
7
*/
8
8
YUI.add('datasource-cache', function(Y) {
9
9
 
10
10
/**
11
 
 * Extends DataSource with caching functionality.
 
11
 * Plugs DataSource with caching functionality.
12
12
 *
13
13
 * @module datasource
14
14
 * @submodule datasource-cache
15
15
 */
16
16
 
17
17
/**
18
 
 * Adds cacheability to the DataSource Utility.
19
 
 * @class DataSourceCache
20
 
 * @extends Cache
21
 
 */    
22
 
var DataSourceCache = function() {
23
 
    DataSourceCache.superclass.constructor.apply(this, arguments);
 
18
 * DataSourceCache extension binds Cache to DataSource.
 
19
 * @class DataSourceCacheExtension
 
20
 */
 
21
var DataSourceCacheExtension = function() {
24
22
};
25
23
 
26
 
Y.mix(DataSourceCache, {
 
24
Y.mix(DataSourceCacheExtension, {
27
25
    /**
28
26
     * The namespace for the plugin. This will be the property on the host which
29
27
     * references the plugin instance.
43
41
     * @type String
44
42
     * @static
45
43
     * @final
46
 
     * @value "dataSourceCache"
 
44
     * @value "dataSourceCacheExtension"
47
45
     */
48
 
    NAME: "dataSourceCache",
49
 
 
50
 
    /////////////////////////////////////////////////////////////////////////////
51
 
    //
52
 
    // DataSourceCache Attributes
53
 
    //
54
 
    /////////////////////////////////////////////////////////////////////////////
55
 
 
56
 
    ATTRS: {
57
 
 
58
 
    }
 
46
    NAME: "dataSourceCacheExtension"
59
47
});
60
48
 
61
 
Y.extend(DataSourceCache, Y.Cache, {
 
49
DataSourceCacheExtension.prototype = {
62
50
    /**
63
51
    * Internal init() handler.
64
52
    *
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");
93
81
        }
94
82
    },
95
 
    
 
83
 
96
84
    /**
97
85
     * Adds data to cache before returning data.
98
86
     *
122
110
     */
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);
128
115
        }
129
116
     }
 
117
};
 
118
 
 
119
Y.namespace("Plugin").DataSourceCacheExtension = DataSourceCacheExtension;
 
120
 
 
121
 
 
122
 
 
123
/**
 
124
 * DataSource plugin adds cache functionality.
 
125
 * @class DataSourceCache
 
126
 * @extends Cache
 
127
 * @uses Plugin.Base, DataSourceCachePlugin
 
128
 */
 
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";
 
134
    return tmpinstance;
 
135
}
 
136
 
 
137
Y.mix(DataSourceCache, {
 
138
    /**
 
139
     * The namespace for the plugin. This will be the property on the host which
 
140
     * references the plugin instance.
 
141
     *
 
142
     * @property NS
 
143
     * @type String
 
144
     * @static
 
145
     * @final
 
146
     * @value "cache"
 
147
     */
 
148
    NS: "cache",
 
149
 
 
150
    /**
 
151
     * Class name.
 
152
     *
 
153
     * @property NAME
 
154
     * @type String
 
155
     * @static
 
156
     * @final
 
157
     * @value "dataSourceCache"
 
158
     */
 
159
    NAME: "dataSourceCache"
130
160
});
131
161
 
132
 
Y.namespace('Plugin').DataSourceCache = DataSourceCache;
133
 
 
134
 
 
135
 
}, '3.1.1' ,{requires:['datasource-local', 'cache']});
 
162
 
 
163
Y.namespace("Plugin").DataSourceCache = DataSourceCache;
 
164
 
 
165
 
 
166
 
 
167
}, '3.2.0' ,{requires:['datasource-local']});