bitsnote-assets 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b9ef4aa3d6eab63f6856156a8d696f38e9da8116
|
|
4
|
+
data.tar.gz: 394474812bce2227f5b6ad3389f8a4a64ee95a32
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ae9453a983c4a42f3dd082846b3759acdf4651d22402c8e019b630e5bd1044cfdc9ae30089d2b7602d607d7c22dac78ceca00927695f1e6c829813a2a39455b
|
|
7
|
+
data.tar.gz: f9f967d5c74e771f8d4723b88c932fdc1cc9054773f3da16529df02358f4ad4fdaeeff81f36d8c9b57b596bf9ec530ff6657b0b70a661bd62d21a91757b7ecd1
|
|
@@ -0,0 +1,2466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Jason Dobry <jason.dobry@gmail.com>
|
|
3
|
+
* @file angular-cache.js
|
|
4
|
+
* @version 3.1.1 - Homepage <https://github.com/jmdobry/angular-cache>
|
|
5
|
+
* @copyright (c) 2013-2014 Jason Dobry <http://www.pseudobry.com>
|
|
6
|
+
* @license MIT <https://github.com/jmdobry/angular-cache/blob/master/LICENSE>
|
|
7
|
+
*
|
|
8
|
+
* @overview angular-cache is a very useful replacement for Angular's $cacheFactory.
|
|
9
|
+
*/
|
|
10
|
+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
11
|
+
/**
|
|
12
|
+
* @method bubbleUp
|
|
13
|
+
* @param {array} heap The heap.
|
|
14
|
+
* @param {function} weightFunc The weight function.
|
|
15
|
+
* @param {number} n The index of the element to bubble up.
|
|
16
|
+
*/
|
|
17
|
+
function bubbleUp(heap, weightFunc, n) {
|
|
18
|
+
var element = heap[n],
|
|
19
|
+
weight = weightFunc(element);
|
|
20
|
+
// When at 0, an element can not go up any further.
|
|
21
|
+
while (n > 0) {
|
|
22
|
+
// Compute the parent element's index, and fetch it.
|
|
23
|
+
var parentN = Math.floor((n + 1) / 2) - 1,
|
|
24
|
+
parent = heap[parentN];
|
|
25
|
+
// If the parent has a lesser weight, things are in order and we
|
|
26
|
+
// are done.
|
|
27
|
+
if (weight >= weightFunc(parent)) {
|
|
28
|
+
break;
|
|
29
|
+
} else {
|
|
30
|
+
heap[parentN] = element;
|
|
31
|
+
heap[n] = parent;
|
|
32
|
+
n = parentN;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @method bubbleDown
|
|
39
|
+
* @param {array} heap The heap.
|
|
40
|
+
* @param {function} weightFunc The weight function.
|
|
41
|
+
* @param {number} n The index of the element to sink down.
|
|
42
|
+
*/
|
|
43
|
+
function bubbleDown(heap, weightFunc, n) {
|
|
44
|
+
var length = heap.length,
|
|
45
|
+
node = heap[n],
|
|
46
|
+
nodeWeight = weightFunc(node);
|
|
47
|
+
|
|
48
|
+
while (true) {
|
|
49
|
+
var child2N = (n + 1) * 2,
|
|
50
|
+
child1N = child2N - 1;
|
|
51
|
+
var swap = null;
|
|
52
|
+
if (child1N < length) {
|
|
53
|
+
var child1 = heap[child1N],
|
|
54
|
+
child1Weight = weightFunc(child1);
|
|
55
|
+
// If the score is less than our node's, we need to swap.
|
|
56
|
+
if (child1Weight < nodeWeight) {
|
|
57
|
+
swap = child1N;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Do the same checks for the other child.
|
|
61
|
+
if (child2N < length) {
|
|
62
|
+
var child2 = heap[child2N],
|
|
63
|
+
child2Weight = weightFunc(child2);
|
|
64
|
+
if (child2Weight < (swap === null ? nodeWeight : weightFunc(heap[child1N]))) {
|
|
65
|
+
swap = child2N;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (swap === null) {
|
|
70
|
+
break;
|
|
71
|
+
} else {
|
|
72
|
+
heap[n] = heap[swap];
|
|
73
|
+
heap[swap] = node;
|
|
74
|
+
n = swap;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @class DSBinaryHeap
|
|
81
|
+
* @desc DSBinaryHeap implementation of a priority queue.
|
|
82
|
+
* @param {function} weightFunc Function that returns the value that should be used for node value comparison.
|
|
83
|
+
* @example
|
|
84
|
+
* angular.module('app').controller(function (DSBinaryHeap) {
|
|
85
|
+
* var bHeap = new DSBinaryHeap(function (x) {
|
|
86
|
+
* return x.value;
|
|
87
|
+
* });
|
|
88
|
+
* );
|
|
89
|
+
*/
|
|
90
|
+
function DSBinaryHeap(weightFunc) {
|
|
91
|
+
if (weightFunc && !angular.isFunction(weightFunc)) {
|
|
92
|
+
throw new Error('DSBinaryHeap(weightFunc): weightFunc: must be a function!');
|
|
93
|
+
}
|
|
94
|
+
weightFunc = weightFunc || function (x) {
|
|
95
|
+
return x;
|
|
96
|
+
};
|
|
97
|
+
this.weightFunc = weightFunc;
|
|
98
|
+
this.heap = [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @method DSBinaryHeap.push
|
|
103
|
+
* @desc Push an element into the binary heap.
|
|
104
|
+
* @param {*} node The element to push into the binary heap.
|
|
105
|
+
*/
|
|
106
|
+
DSBinaryHeap.prototype.push = function (node) {
|
|
107
|
+
this.heap.push(node);
|
|
108
|
+
bubbleUp(this.heap, this.weightFunc, this.heap.length - 1);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @method DSBinaryHeap.peek
|
|
113
|
+
* @desc Return, but do not remove, the minimum element in the binary heap.
|
|
114
|
+
* @returns {*}
|
|
115
|
+
*/
|
|
116
|
+
DSBinaryHeap.prototype.peek = function () {
|
|
117
|
+
return this.heap[0];
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @method DSBinaryHeap.pop
|
|
122
|
+
* @desc Remove and return the minimum element in the binary heap.
|
|
123
|
+
* @returns {*}
|
|
124
|
+
*/
|
|
125
|
+
DSBinaryHeap.prototype.pop = function () {
|
|
126
|
+
var front = this.heap[0],
|
|
127
|
+
end = this.heap.pop();
|
|
128
|
+
if (this.heap.length > 0) {
|
|
129
|
+
this.heap[0] = end;
|
|
130
|
+
bubbleDown(this.heap, this.weightFunc, 0);
|
|
131
|
+
}
|
|
132
|
+
return front;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @method DSBinaryHeap.remove
|
|
137
|
+
* @desc Remove the first node in the priority queue that satisfies angular.equals comparison with
|
|
138
|
+
* the given node.
|
|
139
|
+
* @param {*} node The node to remove.
|
|
140
|
+
* @returns {*} The removed node.
|
|
141
|
+
*/
|
|
142
|
+
DSBinaryHeap.prototype.remove = function (node) {
|
|
143
|
+
var length = this.heap.length;
|
|
144
|
+
for (var i = 0; i < length; i++) {
|
|
145
|
+
if (angular.equals(this.heap[i], node)) {
|
|
146
|
+
var removed = this.heap[i],
|
|
147
|
+
end = this.heap.pop();
|
|
148
|
+
if (i !== length - 1) {
|
|
149
|
+
this.heap[i] = end;
|
|
150
|
+
bubbleUp(this.heap, this.weightFunc, i);
|
|
151
|
+
bubbleDown(this.heap, this.weightFunc, i);
|
|
152
|
+
}
|
|
153
|
+
return removed;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @method DSBinaryHeap.removeAll
|
|
161
|
+
* @desc Remove all nodes from this DSBinaryHeap.
|
|
162
|
+
*/
|
|
163
|
+
DSBinaryHeap.prototype.removeAll = function () {
|
|
164
|
+
this.heap = [];
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @method DSBinaryHeap.size
|
|
169
|
+
* @desc Return the size of the priority queue.
|
|
170
|
+
* @returns {number} The size of the priority queue.
|
|
171
|
+
*/
|
|
172
|
+
DSBinaryHeap.prototype.size = function () {
|
|
173
|
+
return this.heap.length;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @desc Provider for the DSBinaryHeap.
|
|
178
|
+
*/
|
|
179
|
+
function DSBinaryHeapProvider() {
|
|
180
|
+
this.$get = function () {
|
|
181
|
+
return DSBinaryHeap;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
module.exports = {
|
|
186
|
+
DSBinaryHeapProvider: DSBinaryHeapProvider,
|
|
187
|
+
DSBinaryHeap: DSBinaryHeap
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
},{}],2:[function(require,module,exports){
|
|
191
|
+
/**
|
|
192
|
+
* @doc method
|
|
193
|
+
* @id DSCache.methods:destroy
|
|
194
|
+
* @name destroy
|
|
195
|
+
* @description
|
|
196
|
+
* Destroy this cache and all of its data.
|
|
197
|
+
*
|
|
198
|
+
* ## Signature:
|
|
199
|
+
* ```js
|
|
200
|
+
* DSCache#destroy()
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* ## Example:
|
|
204
|
+
* ```js
|
|
205
|
+
* var someCache = DSCacheFactory.get('someCache');
|
|
206
|
+
*
|
|
207
|
+
* someCache.destroy();
|
|
208
|
+
*
|
|
209
|
+
* DSCacheFactory.get('someCache'); // undefined
|
|
210
|
+
* someCache.put('1', 'apple'); // Error
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
module.exports = function destroy() {
|
|
214
|
+
clearInterval(this.$$cacheFlushIntervalId);
|
|
215
|
+
clearInterval(this.$$recycleFreqId);
|
|
216
|
+
this.removeAll();
|
|
217
|
+
if (this.$$storage) {
|
|
218
|
+
this.$$storage.removeItem(this.$$prefix + '.keys');
|
|
219
|
+
this.$$storage.removeItem(this.$$prefix);
|
|
220
|
+
}
|
|
221
|
+
this.$$storage = null;
|
|
222
|
+
this.$$data = null;
|
|
223
|
+
this.$$lruHeap = null;
|
|
224
|
+
this.$$expiresHeap = null;
|
|
225
|
+
this.$$prefix = null;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
},{}],3:[function(require,module,exports){
|
|
229
|
+
var utils = require('../utils');
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @doc method
|
|
233
|
+
* @id DSCache.methods:get
|
|
234
|
+
* @name get
|
|
235
|
+
* @description
|
|
236
|
+
* Retrieve the item with the given key.
|
|
237
|
+
*
|
|
238
|
+
* ## Signature:
|
|
239
|
+
* ```js
|
|
240
|
+
* DSCache#get(key)
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* ## Examples:
|
|
244
|
+
* ```js
|
|
245
|
+
* var cache = DSCacheFactory('cache');
|
|
246
|
+
*
|
|
247
|
+
* cache.put('1', 'apple');
|
|
248
|
+
*
|
|
249
|
+
* cache.get('1'); // "apple"
|
|
250
|
+
* cache.get('2'); // undefined
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* ```js
|
|
254
|
+
* var options = {
|
|
255
|
+
* deleteOnExpire: 'passive',
|
|
256
|
+
* maxAge: 1000
|
|
257
|
+
* },
|
|
258
|
+
* cache = DSCacheFactory('cache', options);
|
|
259
|
+
*
|
|
260
|
+
* cache.put('1', 'apple');
|
|
261
|
+
*
|
|
262
|
+
* cache.get('1'); // "apple"
|
|
263
|
+
*
|
|
264
|
+
* setTimeout(function () {
|
|
265
|
+
* cache.get('1'); // undefined
|
|
266
|
+
* }, 1500);
|
|
267
|
+
* ```
|
|
268
|
+
*
|
|
269
|
+
* ```js
|
|
270
|
+
* var options = {
|
|
271
|
+
* deleteOnExpire: 'passive',
|
|
272
|
+
* maxAge: 1000
|
|
273
|
+
* },
|
|
274
|
+
* cache = DSCacheFactory('cache', options);
|
|
275
|
+
*
|
|
276
|
+
* cache.put('1', 'apple');
|
|
277
|
+
*
|
|
278
|
+
* cache.get('1', {
|
|
279
|
+
* onExpire: function (key, value) {
|
|
280
|
+
* console.log(key, value);
|
|
281
|
+
* }
|
|
282
|
+
* }); // "apple"
|
|
283
|
+
*
|
|
284
|
+
* setTimeout(function () {
|
|
285
|
+
* cache.get('1'); // undefined
|
|
286
|
+
* // "1" "apple" (printed to console)
|
|
287
|
+
* }, 1500);
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* ```js
|
|
291
|
+
* var options = {
|
|
292
|
+
* deleteOnExpire: 'passive',
|
|
293
|
+
* maxAge: 1000,
|
|
294
|
+
* onExpire: function (key, value, done) {
|
|
295
|
+
* console.log('global hit');
|
|
296
|
+
* if (done) {
|
|
297
|
+
* done(key, value);
|
|
298
|
+
* }
|
|
299
|
+
* }
|
|
300
|
+
* },
|
|
301
|
+
* cache = DSCacheFactory('cache', options);
|
|
302
|
+
*
|
|
303
|
+
* cache.put('1', 'apple');
|
|
304
|
+
*
|
|
305
|
+
* cache.get('1', {
|
|
306
|
+
* onExpire: function (key, value) {
|
|
307
|
+
* console.log(key, value);
|
|
308
|
+
* }
|
|
309
|
+
* }); // "apple"
|
|
310
|
+
*
|
|
311
|
+
* setTimeout(function () {
|
|
312
|
+
* cache.get('1'); // undefined
|
|
313
|
+
* // "global hit" (printed to console)
|
|
314
|
+
* // "1" "apple" (printed to console)
|
|
315
|
+
* }, 1500);
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @param {string} key The key of the item to retrieve.
|
|
319
|
+
* @param {object=} options Optional configuration. Properties:
|
|
320
|
+
*
|
|
321
|
+
* - `{function=}` - `onExpire` - Callback to be used if in passive `deleteOnExpire` mode and the requested item has
|
|
322
|
+
* expired. If a global `onExpire` callback exists for this cache, then it will be called with three arguments: `key`,
|
|
323
|
+
* `value`, and `done`, where `done` is the `onExpire` callback passed into the call to `DSCache#get(key[, options])`.
|
|
324
|
+
* (See the last example above.)
|
|
325
|
+
*
|
|
326
|
+
* @returns {*} The item with the given key.
|
|
327
|
+
*/
|
|
328
|
+
module.exports = function get(key, options) {
|
|
329
|
+
var _this = this;
|
|
330
|
+
|
|
331
|
+
if (angular.isArray(key)) {
|
|
332
|
+
var keys = key,
|
|
333
|
+
values = [];
|
|
334
|
+
|
|
335
|
+
angular.forEach(keys, function (key) {
|
|
336
|
+
var value = _this.get(key, options);
|
|
337
|
+
if (value !== null && value !== undefined) {
|
|
338
|
+
values.push(value);
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return values;
|
|
343
|
+
} else {
|
|
344
|
+
key = utils.stringifyNumber(key);
|
|
345
|
+
|
|
346
|
+
if (this.$$disabled) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
options = options || {};
|
|
352
|
+
if (!angular.isString(key)) {
|
|
353
|
+
throw angular.$$minErr('ng')('areq', 'Expected key to be a string! Found: {0}.', typeof key);
|
|
354
|
+
} else if (options && !angular.isObject(options)) {
|
|
355
|
+
throw angular.$$minErr('ng')('areq', 'Expected options to be an object! Found: {0}.', typeof options);
|
|
356
|
+
} else if (options.onExpire && !angular.isFunction(options.onExpire)) {
|
|
357
|
+
throw angular.$$minErr('ng')('areq', 'Expected options.onExpire to be a function! Found: {0}.', typeof options.onExpire);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
var item;
|
|
361
|
+
|
|
362
|
+
if (this.$$storage) {
|
|
363
|
+
var itemJson = this.$$storage.getItem(this.$$prefix + '.data.' + key);
|
|
364
|
+
|
|
365
|
+
if (itemJson) {
|
|
366
|
+
item = angular.fromJson(itemJson);
|
|
367
|
+
} else {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
if (!(key in this.$$data)) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
item = this.$$data[key];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
var value = item.value,
|
|
379
|
+
now = new Date().getTime();
|
|
380
|
+
|
|
381
|
+
if (this.$$storage) {
|
|
382
|
+
this.$$lruHeap.remove({
|
|
383
|
+
key: key,
|
|
384
|
+
accessed: item.accessed
|
|
385
|
+
});
|
|
386
|
+
item.accessed = now;
|
|
387
|
+
this.$$lruHeap.push({
|
|
388
|
+
key: key,
|
|
389
|
+
accessed: now
|
|
390
|
+
});
|
|
391
|
+
} else {
|
|
392
|
+
this.$$lruHeap.remove(item);
|
|
393
|
+
item.accessed = now;
|
|
394
|
+
this.$$lruHeap.push(item);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (this.$$deleteOnExpire === 'passive' && 'expires' in item && item.expires < now) {
|
|
398
|
+
this.remove(key);
|
|
399
|
+
|
|
400
|
+
if (this.$$onExpire) {
|
|
401
|
+
this.$$onExpire(key, item.value, options.onExpire);
|
|
402
|
+
} else if (options.onExpire) {
|
|
403
|
+
options.onExpire(key, item.value);
|
|
404
|
+
}
|
|
405
|
+
value = undefined;
|
|
406
|
+
} else if (this.$$storage) {
|
|
407
|
+
this.$$storage.setItem(this.$$prefix + '.data.' + key, angular.toJson(item));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return value;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
},{"../utils":21}],4:[function(require,module,exports){
|
|
414
|
+
var defaults = require('../defaults'),
|
|
415
|
+
DSBinaryHeap = require('../DSBinaryHeap').DSBinaryHeap;
|
|
416
|
+
|
|
417
|
+
/*!
|
|
418
|
+
* Configure the cache to use webStorage.
|
|
419
|
+
*/
|
|
420
|
+
function _setStorageMode(storageMode, storageImpl) {
|
|
421
|
+
if (!angular.isString(storageMode)) {
|
|
422
|
+
throw angular.$$minErr('ng')('areq', 'Expected storageMode to be a string! Found: {0}.', typeof storageMode);
|
|
423
|
+
} else if (storageMode !== 'memory' && storageMode !== 'localStorage' && storageMode !== 'sessionStorage') {
|
|
424
|
+
throw angular.$$minErr('ng')('areq', 'Expected storageMode to be "memory", "localStorage" or "sessionStorage"! Found: {0}.', storageMode);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
this.$$storageMode = storageMode;
|
|
428
|
+
|
|
429
|
+
if (storageImpl) {
|
|
430
|
+
if (!angular.isObject(storageImpl)) {
|
|
431
|
+
throw angular.$$minErr('ng')('areq', 'Expected storageImpl to be an object! Found: {0}.', typeof storageImpl);
|
|
432
|
+
} else if (!('setItem' in storageImpl) || typeof storageImpl.setItem !== 'function') {
|
|
433
|
+
throw angular.$$minErr('ng')('areq', 'Expected storageImpl to implement "setItem(key, value)"! Found: {0}.', typeof storageImpl.setItem);
|
|
434
|
+
} else if (!('getItem' in storageImpl) || typeof storageImpl.getItem !== 'function') {
|
|
435
|
+
throw angular.$$minErr('ng')('areq', 'Expected storageImpl to implement "getItem(key)"! Found: {0}.', typeof storageImpl.getItem);
|
|
436
|
+
} else if (!('removeItem' in storageImpl) || typeof storageImpl.removeItem !== 'function') {
|
|
437
|
+
throw angular.$$minErr('ng')('areq', 'Expected storageImpl to implement "removeItem(key)"! Found: {0}.', typeof storageImpl.removeItem);
|
|
438
|
+
}
|
|
439
|
+
this.$$storage = storageImpl;
|
|
440
|
+
} else if (this.$$storageMode === 'localStorage') {
|
|
441
|
+
try {
|
|
442
|
+
localStorage.setItem('angular-cache', 'angular-cache');
|
|
443
|
+
localStorage.removeItem('angular-cache');
|
|
444
|
+
this.$$storage = localStorage;
|
|
445
|
+
} catch (e) {
|
|
446
|
+
delete this.$$storage;
|
|
447
|
+
this.$$storageMode = 'memory';
|
|
448
|
+
}
|
|
449
|
+
} else if (this.$$storageMode === 'sessionStorage') {
|
|
450
|
+
try {
|
|
451
|
+
sessionStorage.setItem('angular-cache', 'angular-cache');
|
|
452
|
+
sessionStorage.removeItem('angular-cache');
|
|
453
|
+
this.$$storage = sessionStorage;
|
|
454
|
+
} catch (e) {
|
|
455
|
+
delete this.$$storage;
|
|
456
|
+
this.$$storageMode = 'memory';
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @doc method
|
|
463
|
+
* @id DSCache.methods:setOptions
|
|
464
|
+
* @name setOptions
|
|
465
|
+
* @description
|
|
466
|
+
* Configure this cache with the given options. With this method you can configure all of this cache's settings at once.
|
|
467
|
+
*
|
|
468
|
+
* ## Signature:
|
|
469
|
+
* ```js
|
|
470
|
+
* DSCache#setOptions(cacheOptions[, strict])
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* ## Example:
|
|
474
|
+
* ```js
|
|
475
|
+
* cache.setOptions({
|
|
476
|
+
* maxAge: 60000,
|
|
477
|
+
* deleteOnExpire: 'aggressive',
|
|
478
|
+
* disabled: false
|
|
479
|
+
* });
|
|
480
|
+
* ```
|
|
481
|
+
*
|
|
482
|
+
* @param {object} cacheOptions New configuration options for the cache. Properties:
|
|
483
|
+
*
|
|
484
|
+
* - `{number=}` - `capacity` - Default: `Number.MAX_VALUE`
|
|
485
|
+
* - `{number=}` - `maxAge` - Default: `null`
|
|
486
|
+
* - `{number=}` - `deleteOnExpire` - Default: `none`
|
|
487
|
+
* - `{function=}` - `onExpire` - Default: `null`
|
|
488
|
+
* - `{number=}` - `cacheFlushInterval` - Default: `null`
|
|
489
|
+
* - `{number=}` - `recycleFreq` - Default: `1000`
|
|
490
|
+
* - `{boolean=}` - `disabled` - Default: `false`
|
|
491
|
+
*
|
|
492
|
+
* @param {boolean=} strict If true then any existing configuration will be reset to the defaults before
|
|
493
|
+
* applying the new options, otherwise only the options specified in the options hash will be altered.
|
|
494
|
+
*/
|
|
495
|
+
function _setOptions(cacheOptions, strict) {
|
|
496
|
+
cacheOptions = cacheOptions || {};
|
|
497
|
+
strict = !!strict;
|
|
498
|
+
if (!angular.isObject(cacheOptions)) {
|
|
499
|
+
throw angular.$$minErr('ng')('areq', 'Expected cacheOptions to be an object! Found: {0}.', typeof cacheOptions);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if ('disabled' in cacheOptions) {
|
|
503
|
+
this.$$disabled = !!cacheOptions.disabled;
|
|
504
|
+
} else if (strict) {
|
|
505
|
+
delete this.$$disabled;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if ('capacity' in cacheOptions) {
|
|
509
|
+
this.setCapacity(cacheOptions.capacity);
|
|
510
|
+
} else if (strict) {
|
|
511
|
+
this.setCapacity(null);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if ('deleteOnExpire' in cacheOptions) {
|
|
515
|
+
this.setDeleteOnExpire(cacheOptions.deleteOnExpire);
|
|
516
|
+
} else if (strict) {
|
|
517
|
+
this.setDeleteOnExpire(null);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if ('maxAge' in cacheOptions) {
|
|
521
|
+
this.setMaxAge(cacheOptions.maxAge);
|
|
522
|
+
} else if (strict) {
|
|
523
|
+
this.setMaxAge(null);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if ('recycleFreq' in cacheOptions) {
|
|
527
|
+
this.setRecycleFreq(cacheOptions.recycleFreq);
|
|
528
|
+
} else if (strict) {
|
|
529
|
+
this.setRecycleFreq(null);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if ('cacheFlushInterval' in cacheOptions) {
|
|
533
|
+
this.setCacheFlushInterval(cacheOptions.cacheFlushInterval);
|
|
534
|
+
} else if (strict) {
|
|
535
|
+
this.setCacheFlushInterval(null);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if ('onExpire' in cacheOptions) {
|
|
539
|
+
this.setOnExpire(cacheOptions.onExpire);
|
|
540
|
+
} else if (strict) {
|
|
541
|
+
this.setOnExpire(null);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* @doc function
|
|
547
|
+
* @id DSCache
|
|
548
|
+
* @name DSCache
|
|
549
|
+
* @description
|
|
550
|
+
* Instantiated via `DSCacheFactory(cacheId[, options])`.
|
|
551
|
+
*
|
|
552
|
+
* @param {string} cacheId The id of the new cache.
|
|
553
|
+
* @param {object=} options Configuration options.
|
|
554
|
+
*/
|
|
555
|
+
function DSCache(cacheId, options) {
|
|
556
|
+
|
|
557
|
+
this.$$data = {};
|
|
558
|
+
this.$$id = cacheId;
|
|
559
|
+
this.$$storage = null;
|
|
560
|
+
|
|
561
|
+
this.$$expiresHeap = new DSBinaryHeap(function (x) {
|
|
562
|
+
return x.expires;
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
this.$$lruHeap = new DSBinaryHeap(function (x) {
|
|
566
|
+
return x.accessed;
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
options = options || {};
|
|
570
|
+
|
|
571
|
+
if ('storageMode' in options) {
|
|
572
|
+
_setStorageMode.apply(this, [options.storageMode, options.storageImpl]);
|
|
573
|
+
}
|
|
574
|
+
if ('storagePrefix' in options) {
|
|
575
|
+
this.$$storagePrefix = options.storagePrefix;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
this.$$prefix = this.$$storagePrefix + cacheId;
|
|
579
|
+
|
|
580
|
+
// Initialize this cache with the default and given options
|
|
581
|
+
_setOptions.apply(this, [options, true]);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
for (var key in defaults.defaults) {
|
|
585
|
+
DSCache.prototype['$$' + key] = defaults.defaults[key];
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* @doc method
|
|
590
|
+
* @id DSCache.methods:setOptions
|
|
591
|
+
* @name setOptions
|
|
592
|
+
* @methodOf DSCache
|
|
593
|
+
* @description
|
|
594
|
+
* See [DSCache.setOptions](/documentation/api/angular-cache/DSCache.methods:create).
|
|
595
|
+
*/
|
|
596
|
+
DSCache.prototype.setOptions = _setOptions;
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* @doc method
|
|
600
|
+
* @id DSCache.methods:setCapacity
|
|
601
|
+
* @name setCapacity
|
|
602
|
+
* @methodOf DSCache
|
|
603
|
+
* @description
|
|
604
|
+
* See [DSCache.setCapacity](/documentation/api/angular-cache/DSCache.methods:create).
|
|
605
|
+
*/
|
|
606
|
+
DSCache.prototype.setCapacity = require('./setCapacity');
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* @doc method
|
|
610
|
+
* @id DSCache.methods:setDeleteOnExpire
|
|
611
|
+
* @name setDeleteOnExpire
|
|
612
|
+
* @methodOf DSCache
|
|
613
|
+
* @description
|
|
614
|
+
* See [DSCache.setDeleteOnExpire](/documentation/api/angular-cache/DSCache.methods:create).
|
|
615
|
+
*/
|
|
616
|
+
DSCache.prototype.setDeleteOnExpire = require('./setDeleteOnExpire');
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* @doc method
|
|
620
|
+
* @id DSCache.methods:setMaxAge
|
|
621
|
+
* @name setMaxAge
|
|
622
|
+
* @methodOf DSCache
|
|
623
|
+
* @description
|
|
624
|
+
* See [DSCache.setMaxAge](/documentation/api/angular-cache/DSCache.methods:create).
|
|
625
|
+
*/
|
|
626
|
+
DSCache.prototype.setMaxAge = require('./setMaxAge');
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* @doc method
|
|
630
|
+
* @id DSCache.methods:setRecycleFreq
|
|
631
|
+
* @name setRecycleFreq
|
|
632
|
+
* @methodOf DSCache
|
|
633
|
+
* @description
|
|
634
|
+
* See [DSCache.setRecycleFreq](/documentation/api/angular-cache/DSCache.methods:create).
|
|
635
|
+
*/
|
|
636
|
+
DSCache.prototype.setRecycleFreq = require('./setRecycleFreq');
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* @doc method
|
|
640
|
+
* @id DSCache.methods:setCacheFlushInterval
|
|
641
|
+
* @name setCacheFlushInterval
|
|
642
|
+
* @methodOf DSCache
|
|
643
|
+
* @description
|
|
644
|
+
* See [DSCache.setCacheFlushInterval](/documentation/api/angular-cache/DSCache.methods:create).
|
|
645
|
+
*/
|
|
646
|
+
DSCache.prototype.setCacheFlushInterval = require('./setCacheFlushInterval');
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* @doc method
|
|
650
|
+
* @id DSCache.methods:setOnExpire
|
|
651
|
+
* @name setOnExpire
|
|
652
|
+
* @methodOf DSCache
|
|
653
|
+
* @description
|
|
654
|
+
* See [DSCache.setOnExpire](/documentation/api/angular-cache/DSCache.methods:create).
|
|
655
|
+
*/
|
|
656
|
+
DSCache.prototype.setOnExpire = require('./setOnExpire');
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* @doc method
|
|
660
|
+
* @id DSCache.methods:put
|
|
661
|
+
* @name put
|
|
662
|
+
* @methodOf DSCache
|
|
663
|
+
* @description
|
|
664
|
+
* See [DSCache.put](/documentation/api/angular-cache/DSCache.methods:create).
|
|
665
|
+
*/
|
|
666
|
+
DSCache.prototype.put = require('./put');
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* @doc method
|
|
670
|
+
* @id DSCache.methods:get
|
|
671
|
+
* @name get
|
|
672
|
+
* @methodOf DSCache
|
|
673
|
+
* @description
|
|
674
|
+
* See [DSCache.get](/documentation/api/angular-cache/DSCache.methods:create).
|
|
675
|
+
*/
|
|
676
|
+
DSCache.prototype.get = require('./get');
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* @doc method
|
|
680
|
+
* @id DSCache.methods:remove
|
|
681
|
+
* @name remove
|
|
682
|
+
* @methodOf DSCache
|
|
683
|
+
* @description
|
|
684
|
+
* See [DSCache.remove](/documentation/api/angular-cache/DSCache.methods:create).
|
|
685
|
+
*/
|
|
686
|
+
DSCache.prototype.remove = require('./remove');
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* @doc method
|
|
690
|
+
* @id DSCache.methods:removeAll
|
|
691
|
+
* @name removeAll
|
|
692
|
+
* @methodOf DSCache
|
|
693
|
+
* @description
|
|
694
|
+
* See [DSCache.removeAll](/documentation/api/angular-cache/DSCache.methods:create).
|
|
695
|
+
*/
|
|
696
|
+
DSCache.prototype.removeAll = require('./removeAll');
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* @doc method
|
|
700
|
+
* @id DSCache.methods:removeExpired
|
|
701
|
+
* @name removeExpired
|
|
702
|
+
* @methodOf DSCache
|
|
703
|
+
* @description
|
|
704
|
+
* See [DSCache.removeExpired](/documentation/api/angular-cache/DSCache.methods:create).
|
|
705
|
+
*/
|
|
706
|
+
DSCache.prototype.removeExpired = require('./removeExpired');
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* @doc method
|
|
710
|
+
* @id DSCache.methods:destroy
|
|
711
|
+
* @name destroy
|
|
712
|
+
* @methodOf DSCache
|
|
713
|
+
* @description
|
|
714
|
+
* See [DSCache.destroy](/documentation/api/angular-cache/DSCache.methods:create).
|
|
715
|
+
*/
|
|
716
|
+
DSCache.prototype.destroy = require('./destroy');
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* @doc method
|
|
720
|
+
* @id DSCache.methods:info
|
|
721
|
+
* @name info
|
|
722
|
+
* @methodOf DSCache
|
|
723
|
+
* @description
|
|
724
|
+
* See [DSCache.info](/documentation/api/angular-cache/DSCache.methods:create).
|
|
725
|
+
*/
|
|
726
|
+
DSCache.prototype.info = require('./info');
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* @doc method
|
|
730
|
+
* @id DSCache.methods:keySet
|
|
731
|
+
* @name keySet
|
|
732
|
+
* @methodOf DSCache
|
|
733
|
+
* @description
|
|
734
|
+
* See [DSCache.keySet](/documentation/api/angular-cache/DSCache.methods:create).
|
|
735
|
+
*/
|
|
736
|
+
DSCache.prototype.keySet = require('./keySet');
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* @doc method
|
|
740
|
+
* @id DSCache.methods:keys
|
|
741
|
+
* @name keys
|
|
742
|
+
* @methodOf DSCache
|
|
743
|
+
* @description
|
|
744
|
+
* See [DSCache.keys](/documentation/api/angular-cache/DSCache.methods:create).
|
|
745
|
+
*/
|
|
746
|
+
DSCache.prototype.keys = require('./keys');
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @doc method
|
|
750
|
+
* @id DSCache.methods:disable
|
|
751
|
+
* @name disable
|
|
752
|
+
* @description
|
|
753
|
+
* Disable this cache. Disabling a cache does not remove any data, it just turns DSCache#get and DSCache#put into noops.
|
|
754
|
+
*
|
|
755
|
+
* ## Signature:
|
|
756
|
+
* ```js
|
|
757
|
+
* DSCache#disable()
|
|
758
|
+
* ```
|
|
759
|
+
*
|
|
760
|
+
* ## Example:
|
|
761
|
+
* ```js
|
|
762
|
+
* var cache = DSCacheFactory.get('cache');
|
|
763
|
+
*
|
|
764
|
+
* cache.put('1', 'apple');
|
|
765
|
+
* cache.get('1'); // "apple"
|
|
766
|
+
* cache.info().size; // 1
|
|
767
|
+
*
|
|
768
|
+
* cache.disable();
|
|
769
|
+
* cache.info().size; // 1
|
|
770
|
+
*
|
|
771
|
+
* cache.get('1'); // undefined
|
|
772
|
+
* cache.put('2', 'banana'); // undefined
|
|
773
|
+
* cache.get('2'); // undefined
|
|
774
|
+
* cache.info().size; // 1
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
DSCache.prototype.disable = function () {
|
|
778
|
+
this.$$disabled = true;
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* @doc method
|
|
783
|
+
* @id DSCache.methods:enable
|
|
784
|
+
* @name enable
|
|
785
|
+
* @description
|
|
786
|
+
* Enable this cache.
|
|
787
|
+
*
|
|
788
|
+
* ## Signature:
|
|
789
|
+
* ```js
|
|
790
|
+
* DSCache#enable()
|
|
791
|
+
* ```
|
|
792
|
+
*
|
|
793
|
+
* ## Example:
|
|
794
|
+
* ```js
|
|
795
|
+
* var options = {
|
|
796
|
+
* disabled: true
|
|
797
|
+
* };
|
|
798
|
+
* var cache = DSCacheFactory.get('cache', options);
|
|
799
|
+
*
|
|
800
|
+
* cache.put('1', 'apple');
|
|
801
|
+
* cache.get('1'); // undefined
|
|
802
|
+
*
|
|
803
|
+
* cache.enable();
|
|
804
|
+
*
|
|
805
|
+
* cache.put('1', 'apple');
|
|
806
|
+
* cache.get('1'); // "apple"
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
DSCache.prototype.enable = function () {
|
|
810
|
+
delete this.$$disabled;
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* @doc method
|
|
815
|
+
* @id DSCache.methods:touch
|
|
816
|
+
* @name touch
|
|
817
|
+
* @description
|
|
818
|
+
* Reset the expiry of a single item or all items in the cache.
|
|
819
|
+
*
|
|
820
|
+
* ## Signature:
|
|
821
|
+
* ```js
|
|
822
|
+
* DSCache#touch(key)
|
|
823
|
+
* ```
|
|
824
|
+
*
|
|
825
|
+
* ## Example:
|
|
826
|
+
* ```js
|
|
827
|
+
* cache.touch('1'); // touch one item
|
|
828
|
+
*
|
|
829
|
+
* cache.touch(); // touch all items
|
|
830
|
+
* ```
|
|
831
|
+
*
|
|
832
|
+
* @param {string=} key The key of the item to touch.
|
|
833
|
+
*/
|
|
834
|
+
DSCache.prototype.touch = function (key) {
|
|
835
|
+
if (key) {
|
|
836
|
+
var _this = this;
|
|
837
|
+
var val = this.get(key, {
|
|
838
|
+
onExpire: function (k, v) {
|
|
839
|
+
_this.put(k, v);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
if (val) {
|
|
843
|
+
this.put(key, val);
|
|
844
|
+
}
|
|
845
|
+
} else {
|
|
846
|
+
var keys = this.keys();
|
|
847
|
+
for (var i = 0; i < keys.length; i++) {
|
|
848
|
+
this.touch(keys[i]);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
module.exports = DSCache;
|
|
854
|
+
|
|
855
|
+
},{"../DSBinaryHeap":1,"../defaults":19,"./destroy":2,"./get":3,"./info":5,"./keySet":6,"./keys":7,"./put":8,"./remove":9,"./removeAll":10,"./removeExpired":11,"./setCacheFlushInterval":12,"./setCapacity":13,"./setDeleteOnExpire":14,"./setMaxAge":15,"./setOnExpire":16,"./setRecycleFreq":17}],5:[function(require,module,exports){
|
|
856
|
+
/**
|
|
857
|
+
* @doc method
|
|
858
|
+
* @id DSCache.methods:info
|
|
859
|
+
* @name info
|
|
860
|
+
* @description
|
|
861
|
+
* Return the status of this cache, or if `key` is provided return the status of the item with that key.
|
|
862
|
+
*
|
|
863
|
+
* ## Signature:
|
|
864
|
+
* ```js
|
|
865
|
+
* DSCache#info([key])
|
|
866
|
+
* ```
|
|
867
|
+
*
|
|
868
|
+
* ## Example:
|
|
869
|
+
* ```js
|
|
870
|
+
* var cache = DSCacheFactory('cache');
|
|
871
|
+
*
|
|
872
|
+
* cache.put('1', 'apple');
|
|
873
|
+
* cache.put('2', 'banana');
|
|
874
|
+
*
|
|
875
|
+
* cache.info(); // {
|
|
876
|
+
* // id: 'cache',
|
|
877
|
+
* // capacity: Number.MAX_VALUE,
|
|
878
|
+
* // maxAge: Number.MAX_VALUE,
|
|
879
|
+
* // deleteOnExpire: 'none',
|
|
880
|
+
* // onExpire: null,
|
|
881
|
+
* // cacheFlushInterval: null,
|
|
882
|
+
* // recycleFreq: 1000,
|
|
883
|
+
* // storageMode: 'memory',
|
|
884
|
+
* // storageImpl: null,
|
|
885
|
+
* // disabled: false,
|
|
886
|
+
* // size: 2
|
|
887
|
+
* // }
|
|
888
|
+
*
|
|
889
|
+
* cache.info('1'); // {
|
|
890
|
+
* // created: 1234567890,
|
|
891
|
+
* // accessed: 1234567890,
|
|
892
|
+
* // expires: Number.MAX_VALUE,
|
|
893
|
+
* // isExpired: false
|
|
894
|
+
* // }
|
|
895
|
+
*
|
|
896
|
+
* cache.info('3'); // undefined
|
|
897
|
+
* ```
|
|
898
|
+
*
|
|
899
|
+
* @param {string=} key The key of the item whose status is to be retrieved.
|
|
900
|
+
* @returns {object} The status of this cache or of the item with the given key.
|
|
901
|
+
*/
|
|
902
|
+
module.exports = function info(key) {
|
|
903
|
+
if (key) {
|
|
904
|
+
var item;
|
|
905
|
+
if (this.$$storage) {
|
|
906
|
+
var itemJson = this.$$storage.getItem(this.$$prefix + '.data.' + key);
|
|
907
|
+
|
|
908
|
+
if (itemJson) {
|
|
909
|
+
item = angular.fromJson(itemJson);
|
|
910
|
+
return {
|
|
911
|
+
created: item.created,
|
|
912
|
+
accessed: item.accessed,
|
|
913
|
+
expires: item.expires,
|
|
914
|
+
isExpired: (new Date().getTime() - item.created) > this.$$maxAge
|
|
915
|
+
};
|
|
916
|
+
} else {
|
|
917
|
+
return undefined;
|
|
918
|
+
}
|
|
919
|
+
} else {
|
|
920
|
+
if (key in this.$$data) {
|
|
921
|
+
item = this.$$data[key];
|
|
922
|
+
|
|
923
|
+
return {
|
|
924
|
+
created: item.created,
|
|
925
|
+
accessed: item.accessed,
|
|
926
|
+
expires: item.expires,
|
|
927
|
+
isExpired: (new Date().getTime() - item.created) > this.$$maxAge
|
|
928
|
+
};
|
|
929
|
+
} else {
|
|
930
|
+
return undefined;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
} else {
|
|
934
|
+
return {
|
|
935
|
+
id: this.$$id,
|
|
936
|
+
capacity: this.$$capacity,
|
|
937
|
+
maxAge: this.$$maxAge,
|
|
938
|
+
deleteOnExpire: this.$$deleteOnExpire,
|
|
939
|
+
onExpire: this.$$onExpire,
|
|
940
|
+
cacheFlushInterval: this.$$cacheFlushInterval,
|
|
941
|
+
recycleFreq: this.$$recycleFreq,
|
|
942
|
+
storageMode: this.$$storageMode,
|
|
943
|
+
storageImpl: this.$$storage,
|
|
944
|
+
disabled: this.$$disabled,
|
|
945
|
+
size: this.$$lruHeap && this.$$lruHeap.size() || 0
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
},{}],6:[function(require,module,exports){
|
|
951
|
+
var utils = require('../utils');
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* @doc method
|
|
955
|
+
* @id DSCache.methods:keySet
|
|
956
|
+
* @name keySet
|
|
957
|
+
* @description
|
|
958
|
+
* Return an object of the keys in this cache.
|
|
959
|
+
*
|
|
960
|
+
* ## Signature:
|
|
961
|
+
* ```js
|
|
962
|
+
* DSCache#keySet()
|
|
963
|
+
* ```
|
|
964
|
+
*
|
|
965
|
+
* ## Example:
|
|
966
|
+
* ```js
|
|
967
|
+
* var cache = DSCacheFactory('cache');
|
|
968
|
+
*
|
|
969
|
+
* cache.put('1', 'apple');
|
|
970
|
+
* cache.put('2', 'banana');
|
|
971
|
+
*
|
|
972
|
+
* cache.keys(); // { "1": "1", "2": "2" }
|
|
973
|
+
* ```
|
|
974
|
+
*
|
|
975
|
+
* @returns {object} An object of the keys in this cache.
|
|
976
|
+
*/
|
|
977
|
+
module.exports = function keySet() {
|
|
978
|
+
if (this.$$storage) {
|
|
979
|
+
var keysJson = this.$$storage.getItem(this.$$prefix + '.keys'),
|
|
980
|
+
kSet = {};
|
|
981
|
+
|
|
982
|
+
if (keysJson) {
|
|
983
|
+
var keys = angular.fromJson(keysJson);
|
|
984
|
+
|
|
985
|
+
for (var i = 0; i < keys.length; i++) {
|
|
986
|
+
kSet[keys[i]] = keys[i];
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return kSet;
|
|
990
|
+
} else {
|
|
991
|
+
return utils.keySet(this.$$data);
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
},{"../utils":21}],7:[function(require,module,exports){
|
|
996
|
+
var utils = require('../utils');
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* @doc method
|
|
1000
|
+
* @id DSCache.methods:keys
|
|
1001
|
+
* @name keys
|
|
1002
|
+
* @description
|
|
1003
|
+
* Return an array of the keys in this cache.
|
|
1004
|
+
*
|
|
1005
|
+
* ## Signature:
|
|
1006
|
+
* ```js
|
|
1007
|
+
* DSCache#keys()
|
|
1008
|
+
* ```
|
|
1009
|
+
*
|
|
1010
|
+
* ## Example:
|
|
1011
|
+
* ```js
|
|
1012
|
+
* var cache = DSCacheFactory('cache');
|
|
1013
|
+
*
|
|
1014
|
+
* cache.put('1', 'apple');
|
|
1015
|
+
* cache.put('2', 'banana');
|
|
1016
|
+
*
|
|
1017
|
+
* cache.keys(); // [ "1", "2" ]
|
|
1018
|
+
* ```
|
|
1019
|
+
*
|
|
1020
|
+
* @returns {Array} An array of the keys in this cache.
|
|
1021
|
+
*/
|
|
1022
|
+
module.exports = function keys() {
|
|
1023
|
+
if (this.$$storage) {
|
|
1024
|
+
var keysJson = this.$$storage.getItem(this.$$prefix + '.keys');
|
|
1025
|
+
|
|
1026
|
+
if (keysJson) {
|
|
1027
|
+
return angular.fromJson(keysJson);
|
|
1028
|
+
} else {
|
|
1029
|
+
return [];
|
|
1030
|
+
}
|
|
1031
|
+
} else {
|
|
1032
|
+
return utils.keys(this.$$data);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
},{"../utils":21}],8:[function(require,module,exports){
|
|
1037
|
+
var utils = require('../utils');
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* @doc method
|
|
1041
|
+
* @id DSCache.methods:put
|
|
1042
|
+
* @name put
|
|
1043
|
+
* @description
|
|
1044
|
+
* Insert a value into the cache under the given key.
|
|
1045
|
+
*
|
|
1046
|
+
* ## Signature:
|
|
1047
|
+
* ```js
|
|
1048
|
+
* DSCache#put(key, value)
|
|
1049
|
+
* ```
|
|
1050
|
+
*
|
|
1051
|
+
* ## Example:
|
|
1052
|
+
* ```js
|
|
1053
|
+
* var cache = DSCacheFactory('cache');
|
|
1054
|
+
*
|
|
1055
|
+
* cache.put('1', 'apple');
|
|
1056
|
+
* cache.put('2', 3);
|
|
1057
|
+
* cache.put('3', { stuff: 'more stuff' });
|
|
1058
|
+
*
|
|
1059
|
+
* cache.get('1'); // "apple"
|
|
1060
|
+
* cache.get('2'); // 3
|
|
1061
|
+
* cache.get('3'); // { stuff: 'more stuff' }
|
|
1062
|
+
* cache.get('4'); // undefined
|
|
1063
|
+
* ```
|
|
1064
|
+
*
|
|
1065
|
+
* ## Throws:
|
|
1066
|
+
* - `Error` - `key` must be a string.
|
|
1067
|
+
*
|
|
1068
|
+
* @param {string} key The key under which to store the given value.
|
|
1069
|
+
* @param {*} value The value to store.
|
|
1070
|
+
* @returns {*} The newly stored item.
|
|
1071
|
+
*/
|
|
1072
|
+
module.exports = function put(key, value) {
|
|
1073
|
+
var _this = this;
|
|
1074
|
+
if (this.$$disabled || value === null || value === undefined) {
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if (value && value.then) {
|
|
1078
|
+
value.then(function (v) {
|
|
1079
|
+
if (angular.isObject(v) && 'status' in v && 'data' in v) {
|
|
1080
|
+
_this.put(key, [v.status, v.data, v.headers(), v.statusText]);
|
|
1081
|
+
} else {
|
|
1082
|
+
_this.put(key, v);
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
key = utils.stringifyNumber(key);
|
|
1088
|
+
|
|
1089
|
+
if (!angular.isString(key)) {
|
|
1090
|
+
throw angular.$$minErr('ng')('areq', 'Expected key to be a string! Found: {0}.', typeof key);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
var now = new Date().getTime(),
|
|
1094
|
+
item = {
|
|
1095
|
+
key: key,
|
|
1096
|
+
value: value,
|
|
1097
|
+
created: now,
|
|
1098
|
+
accessed: now
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
item.expires = item.created + this.$$maxAge;
|
|
1102
|
+
|
|
1103
|
+
if (this.$$storage) {
|
|
1104
|
+
var keysJson = this.$$storage.getItem(this.$$prefix + '.keys'),
|
|
1105
|
+
keys = keysJson ? angular.fromJson(keysJson) : [],
|
|
1106
|
+
itemJson = this.$$storage.getItem(this.$$prefix + '.data.' + key);
|
|
1107
|
+
|
|
1108
|
+
// Remove existing
|
|
1109
|
+
if (itemJson) {
|
|
1110
|
+
this.remove(key);
|
|
1111
|
+
}
|
|
1112
|
+
// Add to expires heap
|
|
1113
|
+
this.$$expiresHeap.push({
|
|
1114
|
+
key: key,
|
|
1115
|
+
expires: item.expires
|
|
1116
|
+
});
|
|
1117
|
+
// Add to lru heap
|
|
1118
|
+
this.$$lruHeap.push({
|
|
1119
|
+
key: key,
|
|
1120
|
+
accessed: item.accessed
|
|
1121
|
+
});
|
|
1122
|
+
// Set item
|
|
1123
|
+
this.$$storage.setItem(this.$$prefix + '.data.' + key, angular.toJson(item));
|
|
1124
|
+
var exists = false;
|
|
1125
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1126
|
+
if (keys[i] === key) {
|
|
1127
|
+
exists = true;
|
|
1128
|
+
break;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
if (!exists) {
|
|
1132
|
+
keys.push(key);
|
|
1133
|
+
}
|
|
1134
|
+
this.$$storage.setItem(this.$$prefix + '.keys', angular.toJson(keys));
|
|
1135
|
+
} else {
|
|
1136
|
+
// Remove existing
|
|
1137
|
+
if (this.$$data[key]) {
|
|
1138
|
+
this.remove(key);
|
|
1139
|
+
}
|
|
1140
|
+
// Add to expires heap
|
|
1141
|
+
this.$$expiresHeap.push(item);
|
|
1142
|
+
// Add to lru heap
|
|
1143
|
+
this.$$lruHeap.push(item);
|
|
1144
|
+
// Set item
|
|
1145
|
+
this.$$data[key] = item;
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
// Handle exceeded capacity
|
|
1149
|
+
if (this.$$lruHeap.size() > this.$$capacity) {
|
|
1150
|
+
this.remove(this.$$lruHeap.peek().key);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
return value;
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
},{"../utils":21}],9:[function(require,module,exports){
|
|
1157
|
+
/**
|
|
1158
|
+
* @doc method
|
|
1159
|
+
* @id DSCache.methods:remove
|
|
1160
|
+
* @name remove
|
|
1161
|
+
* @description
|
|
1162
|
+
* Remove the item with the given key.
|
|
1163
|
+
*
|
|
1164
|
+
* ## Signature:
|
|
1165
|
+
* ```js
|
|
1166
|
+
* DSCache#remove(key)
|
|
1167
|
+
* ```
|
|
1168
|
+
*
|
|
1169
|
+
* ## Example:
|
|
1170
|
+
* ```js
|
|
1171
|
+
* var cache = DSCacheFactory('cache');
|
|
1172
|
+
*
|
|
1173
|
+
* cache.put('1', 'apple');
|
|
1174
|
+
*
|
|
1175
|
+
* cache.get('1'); // "apple"
|
|
1176
|
+
*
|
|
1177
|
+
* cache.remove('1'); // "apple"
|
|
1178
|
+
*
|
|
1179
|
+
* cache.get('1'); // undefined
|
|
1180
|
+
* ```
|
|
1181
|
+
*
|
|
1182
|
+
* @param {string} key The key of the item to remove.
|
|
1183
|
+
* @returns {*} The removed item if an item was removed.
|
|
1184
|
+
*/
|
|
1185
|
+
module.exports = function remove(key) {
|
|
1186
|
+
if (this.$$storage) {
|
|
1187
|
+
var itemJson = this.$$storage.getItem(this.$$prefix + '.data.' + key);
|
|
1188
|
+
|
|
1189
|
+
if (itemJson) {
|
|
1190
|
+
var item = angular.fromJson(itemJson);
|
|
1191
|
+
this.$$lruHeap.remove({
|
|
1192
|
+
key: key,
|
|
1193
|
+
accessed: item.accessed
|
|
1194
|
+
});
|
|
1195
|
+
this.$$expiresHeap.remove({
|
|
1196
|
+
key: key,
|
|
1197
|
+
expires: item.expires
|
|
1198
|
+
});
|
|
1199
|
+
this.$$storage.removeItem(this.$$prefix + '.data.' + key);
|
|
1200
|
+
var keysJson = this.$$storage.getItem(this.$$prefix + '.keys'),
|
|
1201
|
+
keys = keysJson ? angular.fromJson(keysJson) : [],
|
|
1202
|
+
index = keys.indexOf(key);
|
|
1203
|
+
|
|
1204
|
+
if (index >= 0) {
|
|
1205
|
+
keys.splice(index, 1);
|
|
1206
|
+
}
|
|
1207
|
+
this.$$storage.setItem(this.$$prefix + '.keys', angular.toJson(keys));
|
|
1208
|
+
return item.value;
|
|
1209
|
+
}
|
|
1210
|
+
} else {
|
|
1211
|
+
var value = this.$$data[key] ? this.$$data[key].value : undefined;
|
|
1212
|
+
this.$$lruHeap.remove(this.$$data[key]);
|
|
1213
|
+
this.$$expiresHeap.remove(this.$$data[key]);
|
|
1214
|
+
this.$$data[key] = null;
|
|
1215
|
+
delete this.$$data[key];
|
|
1216
|
+
return value;
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
},{}],10:[function(require,module,exports){
|
|
1221
|
+
/**
|
|
1222
|
+
* @doc method
|
|
1223
|
+
* @id DSCache.methods:removeAll
|
|
1224
|
+
* @name removeAll
|
|
1225
|
+
* @description
|
|
1226
|
+
* Remove all items from this cache.
|
|
1227
|
+
*
|
|
1228
|
+
* ## Signature:
|
|
1229
|
+
* ```js
|
|
1230
|
+
* DSCache#removeAll()
|
|
1231
|
+
* ```
|
|
1232
|
+
*
|
|
1233
|
+
* ## Example:
|
|
1234
|
+
* ```js
|
|
1235
|
+
* var cache = DSCacheFactory('cache');
|
|
1236
|
+
*
|
|
1237
|
+
* cache.put('1', 'apple');
|
|
1238
|
+
* cache.put('2', 'banana');
|
|
1239
|
+
* cache.info().size; // 2
|
|
1240
|
+
*
|
|
1241
|
+
* cache.get('1'); // "apple"
|
|
1242
|
+
* cache.get('2'); // "banana"
|
|
1243
|
+
*
|
|
1244
|
+
* cache.removeAll();
|
|
1245
|
+
* cache.info().size; // 0
|
|
1246
|
+
*
|
|
1247
|
+
* cache.get('1'); // undefined
|
|
1248
|
+
* cache.get('2'); // undefined
|
|
1249
|
+
* ```
|
|
1250
|
+
*/
|
|
1251
|
+
module.exports = function removeAll() {
|
|
1252
|
+
if (this.$$storage) {
|
|
1253
|
+
this.$$lruHeap.removeAll();
|
|
1254
|
+
this.$$expiresHeap.removeAll();
|
|
1255
|
+
var keysJson = this.$$storage.getItem(this.$$prefix + '.keys');
|
|
1256
|
+
|
|
1257
|
+
if (keysJson) {
|
|
1258
|
+
var keys = angular.fromJson(keysJson);
|
|
1259
|
+
|
|
1260
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1261
|
+
this.remove(keys[i]);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
this.$$storage.setItem(this.$$prefix + '.keys', angular.toJson([]));
|
|
1265
|
+
} else {
|
|
1266
|
+
this.$$lruHeap.removeAll();
|
|
1267
|
+
this.$$expiresHeap.removeAll();
|
|
1268
|
+
for (var key in this.$$data) {
|
|
1269
|
+
this.$$data[key] = null;
|
|
1270
|
+
}
|
|
1271
|
+
this.$$data = {};
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
|
|
1275
|
+
},{}],11:[function(require,module,exports){
|
|
1276
|
+
/**
|
|
1277
|
+
* @doc method
|
|
1278
|
+
* @id DSCache.methods:removeExpired
|
|
1279
|
+
* @name removeExpired
|
|
1280
|
+
* @description
|
|
1281
|
+
* Remove and return all expired items from the cache.
|
|
1282
|
+
*
|
|
1283
|
+
* ## Signature:
|
|
1284
|
+
* ```js
|
|
1285
|
+
* DSCache#removeExpired()
|
|
1286
|
+
* ```
|
|
1287
|
+
*
|
|
1288
|
+
* ## Example:
|
|
1289
|
+
* ```js
|
|
1290
|
+
* var options = {
|
|
1291
|
+
* maxAge: 1000
|
|
1292
|
+
* },
|
|
1293
|
+
* // deleteOnExpire defaults to "none"
|
|
1294
|
+
* cache = DSCacheFactory('cache', options);
|
|
1295
|
+
*
|
|
1296
|
+
* cache.put('1', 'apple');
|
|
1297
|
+
* cache.put('2', 'banana');
|
|
1298
|
+
*
|
|
1299
|
+
* setTimeout(function () {
|
|
1300
|
+
* cache.put('3', 'orange');
|
|
1301
|
+
*
|
|
1302
|
+
* cache.info().size; // 3
|
|
1303
|
+
* cache.info('1').isExpired; // true
|
|
1304
|
+
* cache.info('2').isExpired; // true
|
|
1305
|
+
* cache.info('3').isExpired; // false
|
|
1306
|
+
*
|
|
1307
|
+
* cache.removeExpired(); // { "1": "apple", "2": "banana" }
|
|
1308
|
+
*
|
|
1309
|
+
* cache.info().size; // 1
|
|
1310
|
+
* cache.get('1'); // undefined
|
|
1311
|
+
* cache.get('2'); // undefined
|
|
1312
|
+
* cache.info('3').isExpired; // false
|
|
1313
|
+
* }, 1500);
|
|
1314
|
+
* ```
|
|
1315
|
+
*
|
|
1316
|
+
* @returns {object} The removed items, if any.
|
|
1317
|
+
*/
|
|
1318
|
+
module.exports = function removeExpired() {
|
|
1319
|
+
var now = new Date().getTime(),
|
|
1320
|
+
expired = {},
|
|
1321
|
+
key,
|
|
1322
|
+
expiredItem;
|
|
1323
|
+
|
|
1324
|
+
while ((expiredItem = this.$$expiresHeap.peek()) && expiredItem.expires < now) {
|
|
1325
|
+
expired[expiredItem.key] = expiredItem.value ? expiredItem.value : null;
|
|
1326
|
+
this.$$expiresHeap.pop();
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
if (this.$$storage) {
|
|
1330
|
+
for (key in expired) {
|
|
1331
|
+
var itemJson = this.$$storage.getItem(this.$$prefix + '.data.' + key);
|
|
1332
|
+
if (itemJson) {
|
|
1333
|
+
expired[key] = angular.fromJson(itemJson).value;
|
|
1334
|
+
this.remove(key);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
} else {
|
|
1338
|
+
for (key in expired) {
|
|
1339
|
+
this.remove(key);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
if (this.$$onExpire) {
|
|
1344
|
+
for (key in expired) {
|
|
1345
|
+
this.$$onExpire(key, expired[key]);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
return expired;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
},{}],12:[function(require,module,exports){
|
|
1353
|
+
/**
|
|
1354
|
+
* @doc method
|
|
1355
|
+
* @id DSCache.methods:setCacheFlushInterval
|
|
1356
|
+
* @name setCacheFlushInterval
|
|
1357
|
+
* @description
|
|
1358
|
+
* Set the `cacheFlushInterval` setting for this cache. If set, this setting will cause this cache to periodically
|
|
1359
|
+
* clear itself.
|
|
1360
|
+
*
|
|
1361
|
+
* ## Signature:
|
|
1362
|
+
* ```js
|
|
1363
|
+
* DSCache#setCacheFlushInterval(cacheFlushInterval)
|
|
1364
|
+
* ```
|
|
1365
|
+
*
|
|
1366
|
+
* ## Example:
|
|
1367
|
+
* ```js
|
|
1368
|
+
* var cache = DSCacheFactory('cache');
|
|
1369
|
+
*
|
|
1370
|
+
* cache.put('1', 'apple');
|
|
1371
|
+
* cache.put('2', 'banana');
|
|
1372
|
+
*
|
|
1373
|
+
* cache.info().size; // 2
|
|
1374
|
+
* cache.setCacheFlushInterval(60000);
|
|
1375
|
+
*
|
|
1376
|
+
* setTimeout(function () {
|
|
1377
|
+
* cache.info().size; // 0
|
|
1378
|
+
* }, 90000);
|
|
1379
|
+
* ```
|
|
1380
|
+
*
|
|
1381
|
+
* ## Throws:
|
|
1382
|
+
* - `Error` - `cacheFlushInterval` must be `null` or a number greater than zero.
|
|
1383
|
+
*
|
|
1384
|
+
* @param {number|null} cacheFlushInterval The new cacheFlushInterval for this cache in milliseconds. If
|
|
1385
|
+
* `cacheFlushInterval` is `null` then `cacheFlushInterval` for this cache will be reset to the default (`null`).
|
|
1386
|
+
*/
|
|
1387
|
+
module.exports = function setCacheFlushInterval(cacheFlushInterval) {
|
|
1388
|
+
if (cacheFlushInterval === null) {
|
|
1389
|
+
delete this.$$cacheFlushInterval;
|
|
1390
|
+
} else if (!angular.isNumber(cacheFlushInterval)) {
|
|
1391
|
+
throw angular.$$minErr('ng')('areq', 'Expected cacheFlushInterval to be a number! Found: {0}.', typeof cacheFlushInterval);
|
|
1392
|
+
} else if (cacheFlushInterval < 0) {
|
|
1393
|
+
throw angular.$$minErr('ng')('areq', 'Expected cacheFlushInterval to be greater than zero! Found: {0}.', cacheFlushInterval);
|
|
1394
|
+
} else if (cacheFlushInterval !== this.$$cacheFlushInterval) {
|
|
1395
|
+
this.$$cacheFlushInterval = cacheFlushInterval;
|
|
1396
|
+
clearInterval(this.$$cacheFlushIntervalId);
|
|
1397
|
+
(function (_this) {
|
|
1398
|
+
_this.$$cacheFlushIntervalId = setInterval(function () {
|
|
1399
|
+
_this.removeAll();
|
|
1400
|
+
}, _this.$$cacheFlushInterval);
|
|
1401
|
+
})(this);
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
},{}],13:[function(require,module,exports){
|
|
1406
|
+
/**
|
|
1407
|
+
* @doc method
|
|
1408
|
+
* @id DSCache.methods:setCapacity
|
|
1409
|
+
* @name setCapacity
|
|
1410
|
+
* @description
|
|
1411
|
+
* Set the capacity for this cache.
|
|
1412
|
+
*
|
|
1413
|
+
* ## Signature:
|
|
1414
|
+
* ```js
|
|
1415
|
+
* DSCache#setCapacity(capacity)
|
|
1416
|
+
* ```
|
|
1417
|
+
*
|
|
1418
|
+
* ## Example:
|
|
1419
|
+
* ```js
|
|
1420
|
+
* var smallCache = DSCacheFactory('smallCache', { capacity: 2 });
|
|
1421
|
+
*
|
|
1422
|
+
* smallCache.info().size; // 0
|
|
1423
|
+
*
|
|
1424
|
+
* smallCache.put('1', 'apple');
|
|
1425
|
+
* smallCache.put('2', 'banana');
|
|
1426
|
+
*
|
|
1427
|
+
* smallCache.info().size; // 2
|
|
1428
|
+
*
|
|
1429
|
+
* // Least-recently used items are removed
|
|
1430
|
+
* // when the cache's new capacity exceeds
|
|
1431
|
+
* // its size
|
|
1432
|
+
* smallCache.setCapacity(1);
|
|
1433
|
+
*
|
|
1434
|
+
* smallCache.get('1'); // undefined
|
|
1435
|
+
* smallCache.info().size; // 1
|
|
1436
|
+
* ```
|
|
1437
|
+
*
|
|
1438
|
+
* ## Throws:
|
|
1439
|
+
* - `Error` - `capacity` must be `null` or a number greater than zero.
|
|
1440
|
+
*
|
|
1441
|
+
* @param {number|null} capacity The new capacity for this cache. If `capacity` is `null` then the capacity for this cache
|
|
1442
|
+
* will be reset to the default (`Number.MAX_VALUE`).
|
|
1443
|
+
* @returns {object} Key-value pairs of any items removed because this cache's size exceeds the new capacity.
|
|
1444
|
+
*/
|
|
1445
|
+
module.exports = function setCapacity(capacity) {
|
|
1446
|
+
if (capacity === null) {
|
|
1447
|
+
delete this.$$capacity;
|
|
1448
|
+
} else if (!angular.isNumber(capacity)) {
|
|
1449
|
+
throw angular.$$minErr('ng')('areq', 'Expected capacity to be a number! Found: {0}.', typeof capacity);
|
|
1450
|
+
} else if (capacity < 0) {
|
|
1451
|
+
throw angular.$$minErr('ng')('areq', 'Expected capacity to be greater than zero! Found: {0}.', capacity);
|
|
1452
|
+
} else {
|
|
1453
|
+
this.$$capacity = capacity;
|
|
1454
|
+
}
|
|
1455
|
+
var removed = {};
|
|
1456
|
+
while (this.$$lruHeap.size() > this.$$capacity) {
|
|
1457
|
+
removed[this.$$lruHeap.peek().key] = this.remove(this.$$lruHeap.peek().key);
|
|
1458
|
+
}
|
|
1459
|
+
return removed;
|
|
1460
|
+
};
|
|
1461
|
+
|
|
1462
|
+
},{}],14:[function(require,module,exports){
|
|
1463
|
+
/**
|
|
1464
|
+
* @doc method
|
|
1465
|
+
* @id DSCache.methods:setDeleteOnExpire
|
|
1466
|
+
* @name setDeleteOnExpire
|
|
1467
|
+
* @description
|
|
1468
|
+
* Set the behavior for this cache for when items expire. This setting determines what this cache will do when one of
|
|
1469
|
+
* its items expires.
|
|
1470
|
+
*
|
|
1471
|
+
* ## Possible Values:
|
|
1472
|
+
* - `"none"` - Do nothing when items expire.
|
|
1473
|
+
* - `"passive"` - Do nothing when items expire, but if an expired item is requested, remove it from the cache and return `undefined`.
|
|
1474
|
+
* - `"aggressive"` - Scan for expired items on the interval specified by the `recycleFreq` setting for this cache (defaults
|
|
1475
|
+
* to `1000ms`) and actively remove any expired items.
|
|
1476
|
+
*
|
|
1477
|
+
* ## Signature:
|
|
1478
|
+
* ```js
|
|
1479
|
+
* DSCache#setDeleteOnExpire(deleteOnExpire)
|
|
1480
|
+
* ```
|
|
1481
|
+
*
|
|
1482
|
+
* ## Example:
|
|
1483
|
+
* ```js
|
|
1484
|
+
* var cache = DSCacheFactory('cache');
|
|
1485
|
+
*
|
|
1486
|
+
* cache.put('1', 'apple');
|
|
1487
|
+
*
|
|
1488
|
+
* // Wait a few seconds
|
|
1489
|
+
*
|
|
1490
|
+
* cache.get('1'); // "apple"
|
|
1491
|
+
*
|
|
1492
|
+
* cache.setDeleteOnExpire('aggressive');
|
|
1493
|
+
*
|
|
1494
|
+
* // Wait a few seconds
|
|
1495
|
+
*
|
|
1496
|
+
* cache.get('1'); // undefined
|
|
1497
|
+
* ```
|
|
1498
|
+
*
|
|
1499
|
+
* ## Throws:
|
|
1500
|
+
* - `Error` - `deleteOnExpire` must be `null`, `"none"`, `"passive"` or `"aggressive"`.
|
|
1501
|
+
*
|
|
1502
|
+
* @param {string|null} deleteOnExpire The new deleteOnExpire for this cache. If `deleteOnExpire` is `null` then
|
|
1503
|
+
* `deleteOnExpire` for this cache will be reset to the default (`"none"`).
|
|
1504
|
+
*/
|
|
1505
|
+
module.exports = function setDeleteOnExpire(deleteOnExpire) {
|
|
1506
|
+
if (deleteOnExpire === null) {
|
|
1507
|
+
delete this.$$deleteOnExpire;
|
|
1508
|
+
} else if (!angular.isString(deleteOnExpire)) {
|
|
1509
|
+
throw angular.$$minErr('ng')('areq', 'Expected deleteOnExpire to be a string! Found: {0}.', typeof deleteOnExpire);
|
|
1510
|
+
} else if (deleteOnExpire !== 'none' && deleteOnExpire !== 'passive' && deleteOnExpire !== 'aggressive') {
|
|
1511
|
+
throw angular.$$minErr('ng')('areq', 'Expected deleteOnExpire to be "none", "passive" or "aggressive"! Found: {0}.', deleteOnExpire);
|
|
1512
|
+
} else {
|
|
1513
|
+
this.$$deleteOnExpire = deleteOnExpire;
|
|
1514
|
+
}
|
|
1515
|
+
this.setRecycleFreq(this.$$recycleFreq);
|
|
1516
|
+
};
|
|
1517
|
+
|
|
1518
|
+
},{}],15:[function(require,module,exports){
|
|
1519
|
+
var utils = require('../utils');
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* @doc method
|
|
1523
|
+
* @id DSCache.methods:setMaxAge
|
|
1524
|
+
* @name setMaxAge
|
|
1525
|
+
* @description
|
|
1526
|
+
* Set the `maxAge` setting for this cache. This setting specifies how long items can be in the cache before they expire.
|
|
1527
|
+
*
|
|
1528
|
+
* ## Signature:
|
|
1529
|
+
* ```js
|
|
1530
|
+
* DSCache#setMaxAge(maxAge)
|
|
1531
|
+
* ```
|
|
1532
|
+
*
|
|
1533
|
+
* ## Example:
|
|
1534
|
+
* ```js
|
|
1535
|
+
* var cache = DSCacheFactory('cache', { deleteOnExpire: 'aggressive' });
|
|
1536
|
+
*
|
|
1537
|
+
* // This won't expire for a long time
|
|
1538
|
+
* cache.put('1', 'apple');
|
|
1539
|
+
*
|
|
1540
|
+
* setTimeout(function () {
|
|
1541
|
+
* // 'apple' will be removed because it
|
|
1542
|
+
* // has already been in the cache longer
|
|
1543
|
+
* // than the new maxAge
|
|
1544
|
+
* var removed = cache.setMaxAge(1000);
|
|
1545
|
+
*
|
|
1546
|
+
* removed; // {
|
|
1547
|
+
* // '1': 'apple'
|
|
1548
|
+
* // }
|
|
1549
|
+
* }, 1500);
|
|
1550
|
+
* ```
|
|
1551
|
+
*
|
|
1552
|
+
* ## Throws:
|
|
1553
|
+
* - `Error` - `maxAge must be `null` or a number greater than zero.
|
|
1554
|
+
*
|
|
1555
|
+
* @param {number} maxAge The new maxAge for this cache in milliseconds. If `maxAge` is `null` then `maxAge` for this
|
|
1556
|
+
* cache will be reset to the default (`Number.MAX_VALUE`);
|
|
1557
|
+
* @returns {object} Key-value pairs of any items aggressively removed because they are expired according to the new
|
|
1558
|
+
* `maxAge`. Items are only removed if the `deleteOnExpire` setting for this cache is set to `"aggressive"`.
|
|
1559
|
+
*/
|
|
1560
|
+
module.exports = function setMaxAge(maxAge) {
|
|
1561
|
+
if (maxAge === null) {
|
|
1562
|
+
delete this.$$maxAge;
|
|
1563
|
+
} else if (!angular.isNumber(maxAge)) {
|
|
1564
|
+
throw angular.$$minErr('ng')('areq', 'Expected maxAge to be a number! Found: {0}.', typeof maxAge);
|
|
1565
|
+
} else if (maxAge < 0) {
|
|
1566
|
+
throw angular.$$minErr('ng')('areq', 'Expected maxAge to be greater than zero! Found: {0}.', maxAge);
|
|
1567
|
+
} else {
|
|
1568
|
+
this.$$maxAge = maxAge;
|
|
1569
|
+
}
|
|
1570
|
+
var i, keys, key;
|
|
1571
|
+
|
|
1572
|
+
this.$$expiresHeap.removeAll();
|
|
1573
|
+
|
|
1574
|
+
if (this.$$storage) {
|
|
1575
|
+
var keysJson = this.$$storage.getItem(this.$$prefix + '.keys');
|
|
1576
|
+
|
|
1577
|
+
keys = keysJson ? angular.fromJson(keysJson) : [];
|
|
1578
|
+
|
|
1579
|
+
for (i = 0; i < keys.length; i++) {
|
|
1580
|
+
key = keys[i];
|
|
1581
|
+
var itemJson = this.$$storage.getItem(this.$$prefix + '.data.' + key);
|
|
1582
|
+
|
|
1583
|
+
if (itemJson) {
|
|
1584
|
+
var item = angular.fromJson(itemJson);
|
|
1585
|
+
if (this.$$maxAge === Number.MAX_VALUE) {
|
|
1586
|
+
item.expires = Number.MAX_VALUE;
|
|
1587
|
+
} else {
|
|
1588
|
+
item.expires = item.created + this.$$maxAge;
|
|
1589
|
+
}
|
|
1590
|
+
this.$$expiresHeap.push({
|
|
1591
|
+
key: key,
|
|
1592
|
+
expires: item.expires
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
} else {
|
|
1597
|
+
keys = utils.keys(this.$$data);
|
|
1598
|
+
|
|
1599
|
+
for (i = 0; i < keys.length; i++) {
|
|
1600
|
+
key = keys[i];
|
|
1601
|
+
if (this.$$maxAge === Number.MAX_VALUE) {
|
|
1602
|
+
this.$$data[key].expires = Number.MAX_VALUE;
|
|
1603
|
+
} else {
|
|
1604
|
+
this.$$data[key].expires = this.$$data[key].created + this.$$maxAge;
|
|
1605
|
+
}
|
|
1606
|
+
this.$$expiresHeap.push(this.$$data[key]);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
if (this.$$deleteOnExpire === 'aggressive') {
|
|
1610
|
+
return this.removeExpired();
|
|
1611
|
+
} else {
|
|
1612
|
+
return {};
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
|
|
1616
|
+
},{"../utils":21}],16:[function(require,module,exports){
|
|
1617
|
+
/**
|
|
1618
|
+
* @doc method
|
|
1619
|
+
* @id DSCache.methods:setOnExpire
|
|
1620
|
+
* @name setOnExpire
|
|
1621
|
+
* @description
|
|
1622
|
+
* Set the global `onExpire` callback for this cache.
|
|
1623
|
+
*
|
|
1624
|
+
* ## Signature:
|
|
1625
|
+
* ```js
|
|
1626
|
+
* DSCache#setOnExpire(onExpire)
|
|
1627
|
+
* ```
|
|
1628
|
+
*
|
|
1629
|
+
* ## Examples:
|
|
1630
|
+
* ```js
|
|
1631
|
+
* var options = {
|
|
1632
|
+
* onExpire: function (key, value) {
|
|
1633
|
+
* window.lastExpiredItem = key;
|
|
1634
|
+
* },
|
|
1635
|
+
* maxAge: 1000,
|
|
1636
|
+
* deleteOnExpire: 'aggressive'
|
|
1637
|
+
* };
|
|
1638
|
+
* var cache = DSCacheFactory('cache', options);
|
|
1639
|
+
*
|
|
1640
|
+
* cache.put('1', 'apple');
|
|
1641
|
+
*
|
|
1642
|
+
* setTimeout(function () {
|
|
1643
|
+
* window.lastExpiredItem; // '1'
|
|
1644
|
+
* }, 1500);
|
|
1645
|
+
* ```
|
|
1646
|
+
*
|
|
1647
|
+
* ## Throws:
|
|
1648
|
+
* - `Error` - `cacheFlushInterval` must be `null` or a number greater than zero.
|
|
1649
|
+
*
|
|
1650
|
+
* @param {function|null} onExpire The new onExpire callback for this cache. If `onExpire` is `null` then the onExpire
|
|
1651
|
+
* callback for this cache will be removed.
|
|
1652
|
+
*/
|
|
1653
|
+
module.exports = function setOnExpire(onExpire) {
|
|
1654
|
+
if (onExpire === null) {
|
|
1655
|
+
delete this.$$onExpire;
|
|
1656
|
+
} else if (!angular.isFunction(onExpire)) {
|
|
1657
|
+
throw angular.$$minErr('ng')('areq', 'Expected onExpire to be a function! Found: {0}.', typeof onExpire);
|
|
1658
|
+
} else {
|
|
1659
|
+
this.$$onExpire = onExpire;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1663
|
+
},{}],17:[function(require,module,exports){
|
|
1664
|
+
/**
|
|
1665
|
+
* @doc method
|
|
1666
|
+
* @id DSCache.methods:setRecycleFreq
|
|
1667
|
+
* @name setRecycleFreq
|
|
1668
|
+
* @description
|
|
1669
|
+
* Set the `recycleFreq` setting for this cache. This setting determines how often this cache will scan for expired
|
|
1670
|
+
* items. The cache will only scan for expired items if the `deleteOnExpire` setting for this cache is set to
|
|
1671
|
+
* `"aggressive"`.
|
|
1672
|
+
*
|
|
1673
|
+
* ## Signature:
|
|
1674
|
+
* ```js
|
|
1675
|
+
* DSCache#setRecycleFreq(recycleFreq)
|
|
1676
|
+
* ```
|
|
1677
|
+
*
|
|
1678
|
+
* ## Example:
|
|
1679
|
+
* ```js
|
|
1680
|
+
* var options = {
|
|
1681
|
+
* deleteOnExpire: 'aggressive',
|
|
1682
|
+
* maxAge: 1000
|
|
1683
|
+
* };
|
|
1684
|
+
* var cache = DSCacheFactory('cache', options);
|
|
1685
|
+
*
|
|
1686
|
+
* cache.put('1', 'apple');
|
|
1687
|
+
*
|
|
1688
|
+
* setTimeout(function () {
|
|
1689
|
+
*
|
|
1690
|
+
* cache.get('1'); // undefined
|
|
1691
|
+
* cache.setRecycleFreq(60000);
|
|
1692
|
+
*
|
|
1693
|
+
* // This expires after 1 second, but the cache
|
|
1694
|
+
* // only checks every 60 seconds now
|
|
1695
|
+
* cache.put('1', 'apple');
|
|
1696
|
+
*
|
|
1697
|
+
* setTimeout(function () {
|
|
1698
|
+
* // expired, but won't be removed
|
|
1699
|
+
* // until the next check
|
|
1700
|
+
* cache.get('1'); // "apple"
|
|
1701
|
+
* cache.info('1').isExpired; // true
|
|
1702
|
+
* }, 1500);
|
|
1703
|
+
* }, 1500);
|
|
1704
|
+
* ```
|
|
1705
|
+
*
|
|
1706
|
+
* ## Throws:
|
|
1707
|
+
* - `Error` - `recycleFreq` must be `null` or a number greater than zero.
|
|
1708
|
+
*
|
|
1709
|
+
* @param {number} recycleFreq The new recycleFreq for this cache in milliseconds. If `recycleFreq` is `null` then
|
|
1710
|
+
* `recycleFreq` for this cache will be reset to the default (`1000` milliseconds).
|
|
1711
|
+
*/
|
|
1712
|
+
module.exports = function setRecycleFreq(recycleFreq) {
|
|
1713
|
+
if (recycleFreq === null) {
|
|
1714
|
+
delete this.$$recycleFreq;
|
|
1715
|
+
} else if (!angular.isNumber(recycleFreq)) {
|
|
1716
|
+
throw angular.$$minErr('ng')('areq', 'Expected recycleFreq to be a number! Found: {0}.', typeof recycleFreq);
|
|
1717
|
+
} else if (recycleFreq < 0) {
|
|
1718
|
+
throw angular.$$minErr('ng')('areq', 'Expected recycleFreq to be greater than zero! Found: {0}.', recycleFreq);
|
|
1719
|
+
} else {
|
|
1720
|
+
this.$$recycleFreq = recycleFreq;
|
|
1721
|
+
}
|
|
1722
|
+
clearInterval(this.$$recycleFreqId);
|
|
1723
|
+
if (this.$$deleteOnExpire === 'aggressive') {
|
|
1724
|
+
(function (_this) {
|
|
1725
|
+
_this.$$recycleFreqId = setInterval(function () {
|
|
1726
|
+
_this.removeExpired();
|
|
1727
|
+
}, _this.$$recycleFreq);
|
|
1728
|
+
})(this);
|
|
1729
|
+
} else {
|
|
1730
|
+
delete this.$$recycleFreqId;
|
|
1731
|
+
}
|
|
1732
|
+
};
|
|
1733
|
+
|
|
1734
|
+
},{}],18:[function(require,module,exports){
|
|
1735
|
+
var defaults = require('../defaults'),
|
|
1736
|
+
DSCache = require('../DSCache'),
|
|
1737
|
+
version = '3.1.1';
|
|
1738
|
+
|
|
1739
|
+
/**
|
|
1740
|
+
* @doc function
|
|
1741
|
+
* @id DSCacheFactoryProvider
|
|
1742
|
+
* @name DSCacheFactoryProvider
|
|
1743
|
+
*/
|
|
1744
|
+
function DSCacheFactoryProvider() {
|
|
1745
|
+
|
|
1746
|
+
var config = new defaults.Config();
|
|
1747
|
+
|
|
1748
|
+
this.version = version;
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* @doc method
|
|
1752
|
+
* @id DSCacheFactoryProvider.methods:setCacheDefaults
|
|
1753
|
+
* @name setCacheDefaults
|
|
1754
|
+
* @desc Set the default configuration for all caches created by $angularCacheFactory.
|
|
1755
|
+
* @param {object} options Default configuration options for each new cache.
|
|
1756
|
+
*/
|
|
1757
|
+
this.setCacheDefaults = function (options) {
|
|
1758
|
+
options = options || {};
|
|
1759
|
+
|
|
1760
|
+
if (!angular.isObject(options)) {
|
|
1761
|
+
throw angular.$$minErr('ng')('areq', 'Expected options to be an object! Found: {0}.', typeof options);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
for (var key in defaults.defaults) {
|
|
1765
|
+
if (key in options) {
|
|
1766
|
+
config[key] = options[key];
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
if ('disabled' in options) {
|
|
1770
|
+
config.$$disabled = !!options.disabled;
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
this.$get = function () {
|
|
1775
|
+
var caches = {};
|
|
1776
|
+
|
|
1777
|
+
/*!
|
|
1778
|
+
* @method _keys
|
|
1779
|
+
* @desc Returns an array of the keys of the given collection.
|
|
1780
|
+
* @param {object} collection The collection from which to get the keys.
|
|
1781
|
+
* @returns {array} An array of the keys of the given collection.
|
|
1782
|
+
*/
|
|
1783
|
+
function _keys(collection) {
|
|
1784
|
+
var keys = [], key;
|
|
1785
|
+
for (key in collection) {
|
|
1786
|
+
if (collection.hasOwnProperty(key)) {
|
|
1787
|
+
keys.push(key);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
return keys;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
function createCache(cacheId, options) {
|
|
1794
|
+
if (cacheId in caches) {
|
|
1795
|
+
throw angular.$$minErr('$cacheFactory')('iid', "CacheId '{0}' is already taken!", cacheId);
|
|
1796
|
+
} else if (!angular.isString(cacheId)) {
|
|
1797
|
+
throw angular.$$minErr('ng')('areq', 'Expected cacheId to be a string! Found: {0}.', typeof cacheId);
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
caches[cacheId] = new DSCache(cacheId, angular.extend({}, config, options));
|
|
1801
|
+
caches[cacheId].destroy = function () {
|
|
1802
|
+
this.constructor.prototype.destroy.call(this);
|
|
1803
|
+
delete caches[this.$$id];
|
|
1804
|
+
};
|
|
1805
|
+
return caches[cacheId];
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* @doc function
|
|
1810
|
+
* @id DSCacheFactory
|
|
1811
|
+
* @name DSCacheFactory
|
|
1812
|
+
* @description
|
|
1813
|
+
* Factory function that produces instances of `DSCache`.
|
|
1814
|
+
*
|
|
1815
|
+
* @param {string} cacheId The id of the new cache.
|
|
1816
|
+
* @param {object} options Configuration options. Properties:
|
|
1817
|
+
*
|
|
1818
|
+
* - `{number=}` - `capacity` - Default: `Number.MAX_VALUE`
|
|
1819
|
+
* - `{number=}` - `maxAge` - Default: `null`
|
|
1820
|
+
* - `{number=}` - `deleteOnExpire` - Default: `none`
|
|
1821
|
+
* - `{function=}` - `onExpire` - Default: `null`
|
|
1822
|
+
* - `{number=}` - `cacheFlushInterval` - Default: `null`
|
|
1823
|
+
* - `{number=}` - `recycleFreq` - Default: `1000`
|
|
1824
|
+
* - `{number=}` - `deleteOnExpire` - Default: `null`
|
|
1825
|
+
* - `{string=}` - `storageMode` - Default: `'none`
|
|
1826
|
+
* - `{object=}` - `storageImpl` - Default: `null`
|
|
1827
|
+
* - `{boolean=}` - `disabled` - Default: `false`
|
|
1828
|
+
* - `{string=}` - `storagePrefix` - Default: `"angular-cache.caches."`
|
|
1829
|
+
*
|
|
1830
|
+
* @returns {DSCache} New instance of DSCache.
|
|
1831
|
+
*/
|
|
1832
|
+
function DSCacheFactory(cacheId, options) {
|
|
1833
|
+
return createCache(cacheId, options);
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* @doc method
|
|
1838
|
+
* @id DSCacheFactory.methods:createCache
|
|
1839
|
+
* @name createCache
|
|
1840
|
+
* @description
|
|
1841
|
+
* Factory function that produces instances of `DSCache`.
|
|
1842
|
+
*
|
|
1843
|
+
* @param {string} cacheId The id of the new cache.
|
|
1844
|
+
* @param {object} options Configuration options. Properties:
|
|
1845
|
+
*
|
|
1846
|
+
* - `{number=}` - `capacity` - Default: `Number.MAX_VALUE`
|
|
1847
|
+
* - `{number=}` - `maxAge` - Default: `null`
|
|
1848
|
+
* - `{number=}` - `deleteOnExpire` - Default: `none`
|
|
1849
|
+
* - `{function=}` - `onExpire` - Default: `null`
|
|
1850
|
+
* - `{number=}` - `cacheFlushInterval` - Default: `null`
|
|
1851
|
+
* - `{number=}` - `recycleFreq` - Default: `1000`
|
|
1852
|
+
* - `{number=}` - `deleteOnExpire` - Default: `null`
|
|
1853
|
+
* - `{string=}` - `storageMode` - Default: `'none`
|
|
1854
|
+
* - `{object=}` - `storageImpl` - Default: `null`
|
|
1855
|
+
* - `{boolean=}` - `disabled` - Default: `false`
|
|
1856
|
+
* - `{string=}` - `storagePrefix` - Default: `"angular-cache.caches."`
|
|
1857
|
+
*
|
|
1858
|
+
* @returns {DSCache} New instance of DSCache.
|
|
1859
|
+
*/
|
|
1860
|
+
DSCacheFactory.createCache = createCache;
|
|
1861
|
+
|
|
1862
|
+
DSCacheFactory.version = version;
|
|
1863
|
+
|
|
1864
|
+
/**
|
|
1865
|
+
* @doc method
|
|
1866
|
+
* @id DSCacheFactory.methods:info
|
|
1867
|
+
* @name info
|
|
1868
|
+
* @description
|
|
1869
|
+
* Return the status of `DSCacheFactory`.
|
|
1870
|
+
* @returns {object} The status of `DSCacheFactory`.
|
|
1871
|
+
*/
|
|
1872
|
+
DSCacheFactory.info = function () {
|
|
1873
|
+
var keys = _keys(caches);
|
|
1874
|
+
var info = {
|
|
1875
|
+
size: keys.length,
|
|
1876
|
+
caches: {}
|
|
1877
|
+
};
|
|
1878
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1879
|
+
var key = keys[i];
|
|
1880
|
+
info.caches[key] = caches[key].info();
|
|
1881
|
+
}
|
|
1882
|
+
var c = info.cacheDefaults = angular.extend({}, config);
|
|
1883
|
+
for (var option in defaults.defaults) {
|
|
1884
|
+
if (!(option in c)) {
|
|
1885
|
+
c[option] = config['$$' + option];
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
return info;
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
/**
|
|
1892
|
+
* @doc method
|
|
1893
|
+
* @id DSCacheFactory.methods:get
|
|
1894
|
+
* @name get
|
|
1895
|
+
* @description
|
|
1896
|
+
* Return the cache with the given `cacheId`.
|
|
1897
|
+
* @param {string} cacheId The id of the desired cache.
|
|
1898
|
+
* @returns {DSCache} The cache with the specified `cacheId`.
|
|
1899
|
+
*/
|
|
1900
|
+
DSCacheFactory.get = function (cacheId) {
|
|
1901
|
+
if (!angular.isString(cacheId)) {
|
|
1902
|
+
throw angular.$$minErr('ng')('areq', 'Expected cacheId to be a string! Found: {0}.', typeof cacheId);
|
|
1903
|
+
}
|
|
1904
|
+
return caches[cacheId];
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* @doc method
|
|
1909
|
+
* @id DSCacheFactory.methods:keySet
|
|
1910
|
+
* @name keySet
|
|
1911
|
+
* @description
|
|
1912
|
+
* Return an object containing the `cacheId` of each cache.
|
|
1913
|
+
* @returns {object} An object containing the `cacheId` of each cache.
|
|
1914
|
+
*/
|
|
1915
|
+
DSCacheFactory.keySet = function () {
|
|
1916
|
+
var cacheIds = {}, cacheId;
|
|
1917
|
+
for (cacheId in caches) {
|
|
1918
|
+
if (caches.hasOwnProperty(cacheId)) {
|
|
1919
|
+
cacheIds[cacheId] = cacheId;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
return cacheIds;
|
|
1923
|
+
};
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* @doc method
|
|
1927
|
+
* @id DSCacheFactory.methods:keys
|
|
1928
|
+
* @name keys
|
|
1929
|
+
* @description
|
|
1930
|
+
* Return an array containing the `cacheId` of each cache.
|
|
1931
|
+
* @returns {array} An array containing the `cacheId` of each cache.
|
|
1932
|
+
*/
|
|
1933
|
+
DSCacheFactory.keys = function () {
|
|
1934
|
+
return _keys(caches);
|
|
1935
|
+
};
|
|
1936
|
+
|
|
1937
|
+
/**
|
|
1938
|
+
* @doc method
|
|
1939
|
+
* @id DSCacheFactory.methods:destroyAll
|
|
1940
|
+
* @name destroyAll
|
|
1941
|
+
* @description
|
|
1942
|
+
* Destroy all caches.
|
|
1943
|
+
*
|
|
1944
|
+
* ## Signature:
|
|
1945
|
+
* ```js
|
|
1946
|
+
* DSCacheFactory.destroyAll()
|
|
1947
|
+
* ```
|
|
1948
|
+
*
|
|
1949
|
+
* ## Example:
|
|
1950
|
+
* ```js
|
|
1951
|
+
* var newCache = DSCacheFactory('newCache');
|
|
1952
|
+
* var otherCache = DSCacheFactory('otherCache');
|
|
1953
|
+
*
|
|
1954
|
+
* newCache.info().size; // 0
|
|
1955
|
+
* otherCache.info().size; // 0
|
|
1956
|
+
*
|
|
1957
|
+
* newCache.put('1', 'apple');
|
|
1958
|
+
* newCache.put('2', 'banana');
|
|
1959
|
+
* otherCache.put('abcd', 'horse');
|
|
1960
|
+
*
|
|
1961
|
+
* newCache.info().size; // 2
|
|
1962
|
+
* otherCache.info().size; // 1
|
|
1963
|
+
*
|
|
1964
|
+
* DSCacheFactory.destroyAll();
|
|
1965
|
+
*
|
|
1966
|
+
* newCache.info().size; // Error thrown
|
|
1967
|
+
* otherCache.info().size; // Error thrown
|
|
1968
|
+
*
|
|
1969
|
+
* DSCacheFactory.get('newCache'); // undefined
|
|
1970
|
+
* DSCacheFactory.get('otherCache'); // undefined
|
|
1971
|
+
* ```
|
|
1972
|
+
*/
|
|
1973
|
+
DSCacheFactory.destroyAll = function () {
|
|
1974
|
+
for (var cacheId in caches) {
|
|
1975
|
+
caches[cacheId].destroy();
|
|
1976
|
+
}
|
|
1977
|
+
caches = {};
|
|
1978
|
+
};
|
|
1979
|
+
|
|
1980
|
+
/**
|
|
1981
|
+
* @doc method
|
|
1982
|
+
* @id DSCacheFactory.methods:clearAll
|
|
1983
|
+
* @name clearAll
|
|
1984
|
+
* @description
|
|
1985
|
+
* Clear the contents of all caches.
|
|
1986
|
+
*
|
|
1987
|
+
* ## Signature:
|
|
1988
|
+
* ```js
|
|
1989
|
+
* DSCacheFactory.clearAll()
|
|
1990
|
+
* ```
|
|
1991
|
+
*
|
|
1992
|
+
* ## Example:
|
|
1993
|
+
* ```js
|
|
1994
|
+
* var newCache = DSCacheFactory('newCache');
|
|
1995
|
+
* var otherCache = DSCacheFactory('otherCache');
|
|
1996
|
+
*
|
|
1997
|
+
* newCache.info().size; // 0
|
|
1998
|
+
* otherCache.info().size; // 0
|
|
1999
|
+
*
|
|
2000
|
+
* newCache.put('1', 'apple');
|
|
2001
|
+
* newCache.put('2', 'banana');
|
|
2002
|
+
* otherCache.put('abcd', 'horse');
|
|
2003
|
+
*
|
|
2004
|
+
* newCache.info().size; // 2
|
|
2005
|
+
* otherCache.info().size; // 1
|
|
2006
|
+
*
|
|
2007
|
+
* DSCacheFactory.clearAll();
|
|
2008
|
+
*
|
|
2009
|
+
* newCache.info().size; // 0
|
|
2010
|
+
* otherCache.info().size; // 0
|
|
2011
|
+
* ```
|
|
2012
|
+
*/
|
|
2013
|
+
DSCacheFactory.clearAll = function () {
|
|
2014
|
+
for (var cacheId in caches) {
|
|
2015
|
+
caches[cacheId].removeAll();
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
|
|
2019
|
+
/**
|
|
2020
|
+
* @doc method
|
|
2021
|
+
* @id DSCacheFactory.methods:enableAll
|
|
2022
|
+
* @name enableAll
|
|
2023
|
+
* @description
|
|
2024
|
+
* Enable any disabled caches.
|
|
2025
|
+
*
|
|
2026
|
+
* ## Signature:
|
|
2027
|
+
* ```js
|
|
2028
|
+
* DSCacheFactory.enableAll()
|
|
2029
|
+
* ```
|
|
2030
|
+
*
|
|
2031
|
+
* ## Example:
|
|
2032
|
+
* ```js
|
|
2033
|
+
* var newCache = DSCacheFactory('newCache', { disabled: true });
|
|
2034
|
+
* var otherCache = DSCacheFactory('otherCache', { disabled: true });
|
|
2035
|
+
*
|
|
2036
|
+
* newCache.info().disabled; // true
|
|
2037
|
+
* otherCache.info().disabled; // true
|
|
2038
|
+
*
|
|
2039
|
+
* DSCacheFactory.enableAll();
|
|
2040
|
+
*
|
|
2041
|
+
* newCache.info().disabled; // false
|
|
2042
|
+
* otherCache.info().disabled; // false
|
|
2043
|
+
* ```
|
|
2044
|
+
*/
|
|
2045
|
+
DSCacheFactory.enableAll = function () {
|
|
2046
|
+
for (var cacheId in caches) {
|
|
2047
|
+
caches[cacheId].$$disabled = false;
|
|
2048
|
+
}
|
|
2049
|
+
};
|
|
2050
|
+
|
|
2051
|
+
/**
|
|
2052
|
+
* @doc method
|
|
2053
|
+
* @id DSCacheFactory.methods:disableAll
|
|
2054
|
+
* @name disableAll
|
|
2055
|
+
* @description
|
|
2056
|
+
* Disable all caches.
|
|
2057
|
+
*
|
|
2058
|
+
* ## Signature:
|
|
2059
|
+
* ```js
|
|
2060
|
+
* DSCacheFactory.disableAll()
|
|
2061
|
+
* ```
|
|
2062
|
+
*
|
|
2063
|
+
* ## Example:
|
|
2064
|
+
* ```js
|
|
2065
|
+
* var newCache = DSCacheFactory('newCache');
|
|
2066
|
+
* var otherCache = DSCacheFactory('otherCache');
|
|
2067
|
+
*
|
|
2068
|
+
* newCache.info().disabled; // false
|
|
2069
|
+
* otherCache.info().disabled; // false
|
|
2070
|
+
*
|
|
2071
|
+
* DSCacheFactory.disableAll();
|
|
2072
|
+
*
|
|
2073
|
+
* newCache.info().disabled; // true
|
|
2074
|
+
* otherCache.info().disabled; // true
|
|
2075
|
+
* ```
|
|
2076
|
+
*/
|
|
2077
|
+
DSCacheFactory.disableAll = function () {
|
|
2078
|
+
for (var cacheId in caches) {
|
|
2079
|
+
caches[cacheId].$$disabled = true;
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
return DSCacheFactory;
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
module.exports = DSCacheFactoryProvider;
|
|
2088
|
+
|
|
2089
|
+
},{"../DSCache":4,"../defaults":19}],19:[function(require,module,exports){
|
|
2090
|
+
var defaults = {
|
|
2091
|
+
/**
|
|
2092
|
+
* @doc overview
|
|
2093
|
+
* @id capacity
|
|
2094
|
+
* @name capacity
|
|
2095
|
+
* @description
|
|
2096
|
+
* __Default:__ `Number.MAX_VALUE`
|
|
2097
|
+
*
|
|
2098
|
+
* This option limits the capacity of a cache. With a maximum capacity set, a cache operates as an LRU cache,
|
|
2099
|
+
* deleting the least-recently-used item when the cache exceeds capacity.
|
|
2100
|
+
*
|
|
2101
|
+
* This option is dynamically configurable. Must be a number (milliseconds) greater than zero.
|
|
2102
|
+
*
|
|
2103
|
+
* ### Where can it be used?
|
|
2104
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2105
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2106
|
+
* - `DSCache.setCapacity(capacity)`
|
|
2107
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2108
|
+
*/
|
|
2109
|
+
capacity: Number.MAX_VALUE,
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* @doc overview
|
|
2113
|
+
* @id maxAge
|
|
2114
|
+
* @name maxAge
|
|
2115
|
+
* @description
|
|
2116
|
+
* __Default:__ `Number.MAX_VALUE`
|
|
2117
|
+
*
|
|
2118
|
+
* This option determines how long an item is in a cache before the item expires.. With `maxAge` set, items are
|
|
2119
|
+
* marked as expired when their time in a cache exceeds `maxAge`. A cache's behavior when an item expires is
|
|
2120
|
+
* determined by the [deleteOnExpire](/documentation/api/angular-cache/deleteOnExpire) option.
|
|
2121
|
+
*
|
|
2122
|
+
* This option is dynamically configurable. Must be a number (milliseconds) greater than zero.
|
|
2123
|
+
*
|
|
2124
|
+
* ### Where can it be used?
|
|
2125
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2126
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2127
|
+
* - `DSCache.setMaxAge(maxAge)`
|
|
2128
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2129
|
+
*/
|
|
2130
|
+
maxAge: Number.MAX_VALUE,
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* @doc overview
|
|
2134
|
+
* @id deleteOnExpire
|
|
2135
|
+
* @name deleteOnExpire
|
|
2136
|
+
* @description
|
|
2137
|
+
* __Default:__ `"none"`
|
|
2138
|
+
*
|
|
2139
|
+
* This option determines how long an item is in a cache before the item expires.. With `maxAge` set, items are
|
|
2140
|
+
* marked as expired when their time in a cache exceeds `maxAge`. A cache's behavior when an item expires is
|
|
2141
|
+
* determined by the [deleteOnExpire](/documentation/api/angular-cache/deleteOnExpire) option.
|
|
2142
|
+
*
|
|
2143
|
+
* This option is dynamically configurable. Must be `"none"`, `"passive"` or `"aggressive"`.
|
|
2144
|
+
*
|
|
2145
|
+
* #### "none"
|
|
2146
|
+
* A cache will do nothing when its items expire.
|
|
2147
|
+
*
|
|
2148
|
+
* #### "passive"
|
|
2149
|
+
* A cache will do nothing when its items expire. If an expired item is request it is removed from the cache and
|
|
2150
|
+
* `undefined` is returned.
|
|
2151
|
+
*
|
|
2152
|
+
* #### "aggressive"
|
|
2153
|
+
* A cache will periodically scan for expired items and actively remove them from the cache if any are found. The
|
|
2154
|
+
* frequency of the scan is determined by the [recycleFreq](/documentation/api/angular-cache/recycleFreq) option.
|
|
2155
|
+
*
|
|
2156
|
+
* ### Where can it be used?
|
|
2157
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2158
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2159
|
+
* - `DSCache.setRecycleFreq(recycleFreq)`
|
|
2160
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2161
|
+
*/
|
|
2162
|
+
deleteOnExpire: 'none',
|
|
2163
|
+
|
|
2164
|
+
/**
|
|
2165
|
+
* @doc overview
|
|
2166
|
+
* @id onExpire
|
|
2167
|
+
* @name onExpire
|
|
2168
|
+
* @description
|
|
2169
|
+
* __Default:__ `"none"`
|
|
2170
|
+
*
|
|
2171
|
+
* This option is a callback function which will be executed whenever an expired item is removed from a cache by
|
|
2172
|
+
* either requesting an expired item while the cache is in `"passive"` `deleteOnExpire` mode, or when an expired
|
|
2173
|
+
* item is actively removed when the cache is in `"aggressive"` `deleteOnExpire` mode.
|
|
2174
|
+
*
|
|
2175
|
+
* This option is dynamically configurable. Must be a function. Will be passed the `key` and `value` of the expired
|
|
2176
|
+
* item. Will be passed a third `done` argument (if in `"passive"` `deleteOnExpire` mode) which is the `onExpire`
|
|
2177
|
+
* argument passed to [DSCache#get(key[, options])](/documentation/api/angular-cache/DSCache.methods:get).
|
|
2178
|
+
*
|
|
2179
|
+
* ### Where can it be used?
|
|
2180
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2181
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2182
|
+
* - `DSCache.setOnExpire(onExpire)`
|
|
2183
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2184
|
+
*/
|
|
2185
|
+
onExpire: null,
|
|
2186
|
+
|
|
2187
|
+
/**
|
|
2188
|
+
* @doc overview
|
|
2189
|
+
* @id cacheFlushInterval
|
|
2190
|
+
* @name cacheFlushInterval
|
|
2191
|
+
* @description
|
|
2192
|
+
* __Default:__ `null`
|
|
2193
|
+
*
|
|
2194
|
+
* This option, if set, will cause a cache to periodically clear itself of all data.
|
|
2195
|
+
*
|
|
2196
|
+
* This option is dynamically configurable. Must be a number (milliseconds) greater than zero.
|
|
2197
|
+
*
|
|
2198
|
+
* ### Where can it be used?
|
|
2199
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2200
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2201
|
+
* - `DSCache.setCacheFlushInterval(cacheFlushInterval)`
|
|
2202
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2203
|
+
*/
|
|
2204
|
+
cacheFlushInterval: null,
|
|
2205
|
+
|
|
2206
|
+
/**
|
|
2207
|
+
* @doc overview
|
|
2208
|
+
* @id recycleFreq
|
|
2209
|
+
* @name recycleFreq
|
|
2210
|
+
* @description
|
|
2211
|
+
* __Default:__ `1000`
|
|
2212
|
+
*
|
|
2213
|
+
* This option determines how often a cache will scan for expired items when in `"aggressive"` `deleteOnExpire`
|
|
2214
|
+
* mode.
|
|
2215
|
+
*
|
|
2216
|
+
* This option is dynamically configurable. Must be a number (milliseconds) greater than zero.
|
|
2217
|
+
*
|
|
2218
|
+
* ### Where can it be used?
|
|
2219
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2220
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2221
|
+
* - `DSCache.setRecycleFreq(recycleFreq)`
|
|
2222
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2223
|
+
*/
|
|
2224
|
+
recycleFreq: 1000,
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* @doc overview
|
|
2228
|
+
* @id storageMode
|
|
2229
|
+
* @name storageMode
|
|
2230
|
+
* @description
|
|
2231
|
+
* __Default:__ `"memory"`
|
|
2232
|
+
*
|
|
2233
|
+
* This option determines the storage mode for a cache.
|
|
2234
|
+
*
|
|
2235
|
+
* #### "memory"
|
|
2236
|
+
* All data will be held in memory.
|
|
2237
|
+
*
|
|
2238
|
+
* #### "localStorage"
|
|
2239
|
+
* Data will be held in `localStorage`, if available (or
|
|
2240
|
+
* [storageImpl](/documentation/api/angular-cache/storageImpl) is provided).
|
|
2241
|
+
*
|
|
2242
|
+
* #### "sessionStorage"
|
|
2243
|
+
* Data will be held in `sessionStorage`, if available (or
|
|
2244
|
+
* [storageImpl](/documentation/api/angular-cache/storageImpl) is provided).
|
|
2245
|
+
*
|
|
2246
|
+
* This option is NOT dynamically configurable. Must be `"memory"`, `"localStorage"` or `"sessionStorage"`.
|
|
2247
|
+
*
|
|
2248
|
+
* ### Where can it be used?
|
|
2249
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2250
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2251
|
+
*/
|
|
2252
|
+
storageMode: 'memory',
|
|
2253
|
+
|
|
2254
|
+
/**
|
|
2255
|
+
* @doc overview
|
|
2256
|
+
* @id storageImpl
|
|
2257
|
+
* @name storageImpl
|
|
2258
|
+
* @description
|
|
2259
|
+
* __Default:__ `null`
|
|
2260
|
+
*
|
|
2261
|
+
* This option is available if you want to provide a custom `localStorage` or `sessionStorage` implementation.
|
|
2262
|
+
*
|
|
2263
|
+
* This option is NOT dynamically configurable. Must be an object that implements `setItem(key, value)`,
|
|
2264
|
+
* `getItem(key)` and `removeItem(key)`.
|
|
2265
|
+
*
|
|
2266
|
+
* ### Where can it be used?
|
|
2267
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2268
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2269
|
+
*/
|
|
2270
|
+
storageImpl: null,
|
|
2271
|
+
|
|
2272
|
+
/**
|
|
2273
|
+
* @doc overview
|
|
2274
|
+
* @id disabled
|
|
2275
|
+
* @name disabled
|
|
2276
|
+
* @description
|
|
2277
|
+
* __Default:__ `false`
|
|
2278
|
+
*
|
|
2279
|
+
* This option disables or enables cache.
|
|
2280
|
+
*
|
|
2281
|
+
* This option is dynamically configurable. Must be `true` or `false`.
|
|
2282
|
+
*
|
|
2283
|
+
* ### Where can it be used?
|
|
2284
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2285
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2286
|
+
* - `DSCache.setOptions(options[, strict])`
|
|
2287
|
+
*
|
|
2288
|
+
* or just use [DSCache#disable()](/documentation/api/angular-cache/DSCache.methods:disable) or
|
|
2289
|
+
* [DSCache#enable()](/documentation/api/angular-cache/DSCache.methods:enable).
|
|
2290
|
+
*/
|
|
2291
|
+
disabled: false,
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* @doc overview
|
|
2295
|
+
* @id storagePrefix
|
|
2296
|
+
* @name storagePrefix
|
|
2297
|
+
* @description
|
|
2298
|
+
* __Default:__ `"angular-cache.caches."`
|
|
2299
|
+
*
|
|
2300
|
+
* This option determines the namespace for a cache when `storageMode` is `"localStorage"` or `"sessionStorage"`.
|
|
2301
|
+
* Setting this value to something like `"ac."` will save space when using WebStorage.
|
|
2302
|
+
*
|
|
2303
|
+
* This option is NOT dynamically configurable. Must be a string.
|
|
2304
|
+
*
|
|
2305
|
+
* ### Where can it be used?
|
|
2306
|
+
* - `DSCacheFactoryProvider.setCacheDefaults(options)`
|
|
2307
|
+
* - `DSCacheFactory(cacheId[, options])`
|
|
2308
|
+
*/
|
|
2309
|
+
storagePrefix: 'angular-cache.caches.'
|
|
2310
|
+
};
|
|
2311
|
+
|
|
2312
|
+
function Config() {
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
for (var option in defaults) {
|
|
2316
|
+
Config.prototype['$$' + option] = defaults[option];
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
module.exports = {
|
|
2320
|
+
Config: Config,
|
|
2321
|
+
defaults: defaults
|
|
2322
|
+
};
|
|
2323
|
+
|
|
2324
|
+
},{}],20:[function(require,module,exports){
|
|
2325
|
+
(function (window, angular, undefined) {
|
|
2326
|
+
'use strict';
|
|
2327
|
+
|
|
2328
|
+
angular.$$minErr = angular.$$minErr || function minErr(module) {
|
|
2329
|
+
return function () {
|
|
2330
|
+
var code = arguments[0],
|
|
2331
|
+
prefix = '[' + (module ? module + ':' : '') + code + '] ',
|
|
2332
|
+
template = arguments[1],
|
|
2333
|
+
templateArgs = arguments,
|
|
2334
|
+
stringify = function (obj) {
|
|
2335
|
+
if (typeof obj === 'function') {
|
|
2336
|
+
return obj.toString().replace(/ \{[\s\S]*$/, '');
|
|
2337
|
+
} else if (typeof obj === 'undefined') {
|
|
2338
|
+
return 'undefined';
|
|
2339
|
+
} else if (typeof obj !== 'string') {
|
|
2340
|
+
return JSON.stringify(obj);
|
|
2341
|
+
}
|
|
2342
|
+
return obj;
|
|
2343
|
+
},
|
|
2344
|
+
message, i;
|
|
2345
|
+
|
|
2346
|
+
message = prefix + template.replace(/\{\d+\}/g, function (match) {
|
|
2347
|
+
var index = +match.slice(1, -1), arg;
|
|
2348
|
+
|
|
2349
|
+
if (index + 2 < templateArgs.length) {
|
|
2350
|
+
arg = templateArgs[index + 2];
|
|
2351
|
+
if (typeof arg === 'function') {
|
|
2352
|
+
return arg.toString().replace(/ ?\{[\s\S]*$/, '');
|
|
2353
|
+
} else if (typeof arg === 'undefined') {
|
|
2354
|
+
return 'undefined';
|
|
2355
|
+
} else if (typeof arg !== 'string') {
|
|
2356
|
+
return angular.toJson(arg);
|
|
2357
|
+
}
|
|
2358
|
+
return arg;
|
|
2359
|
+
}
|
|
2360
|
+
return match;
|
|
2361
|
+
});
|
|
2362
|
+
|
|
2363
|
+
message = message + '\nhttp://errors.angularjs.org/' + angular.version.full + '/' +
|
|
2364
|
+
(module ? module + '/' : '') + code;
|
|
2365
|
+
for (i = 2; i < arguments.length; i++) {
|
|
2366
|
+
message = message + (i == 2 ? '?' : '&') + 'p' + (i - 2) + '=' +
|
|
2367
|
+
encodeURIComponent(stringify(arguments[i]));
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
return new Error(message);
|
|
2371
|
+
};
|
|
2372
|
+
};
|
|
2373
|
+
|
|
2374
|
+
|
|
2375
|
+
angular.module('angular-data.DSBinaryHeap', [])
|
|
2376
|
+
.provider('DSBinaryHeap', require('./DSBinaryHeap').DSBinaryHeapProvider);
|
|
2377
|
+
|
|
2378
|
+
/**
|
|
2379
|
+
* @doc overview
|
|
2380
|
+
* @id angular-cache
|
|
2381
|
+
* @name Overview
|
|
2382
|
+
* @description
|
|
2383
|
+
* __Version:__ 3.1.1
|
|
2384
|
+
*
|
|
2385
|
+
* ## Install
|
|
2386
|
+
*
|
|
2387
|
+
* #### Bower
|
|
2388
|
+
* ```text
|
|
2389
|
+
* bower install angular-cache
|
|
2390
|
+
* ```
|
|
2391
|
+
*
|
|
2392
|
+
* Load `dist/angular-cache.js` or `dist/angular-cache.min.js` onto your web page after Angular.js.
|
|
2393
|
+
*
|
|
2394
|
+
* #### Npm
|
|
2395
|
+
* ```text
|
|
2396
|
+
* npm install angular-cache
|
|
2397
|
+
* ```
|
|
2398
|
+
*
|
|
2399
|
+
* Load `dist/angular-cache.js` or `dist/angular-cache.min.js` onto your web page after Angular.js. Angular-cache is
|
|
2400
|
+
* also consumable by Browserify and you should be able to `require('angular-cache')`. The `main` file is `src/index.js`.
|
|
2401
|
+
*
|
|
2402
|
+
* #### Manual download
|
|
2403
|
+
* Download angular-cache.3.1.1.js from the [Releases](https://github.com/jmdobry/angular-cache/releases)
|
|
2404
|
+
* section of the angular-cache GitHub project.
|
|
2405
|
+
*
|
|
2406
|
+
* ## Load into Angular
|
|
2407
|
+
* Your Angular app must depend on the module `"angular-data.DSCacheFactory"` in order to use angular-cache. Loading
|
|
2408
|
+
* angular-cache into your app allows you to inject the following:
|
|
2409
|
+
*
|
|
2410
|
+
* - `DSCacheFactory`
|
|
2411
|
+
* - `DSBinaryHeap`
|
|
2412
|
+
*
|
|
2413
|
+
* [DSCacheFactory](/documentation/api/api/DSCacheFactory) is a factory function that produces instances of
|
|
2414
|
+
* [DSCache](/documentation/api/api/DSCache), which is API compatible with caches produced by Angular's
|
|
2415
|
+
* [$cacheFactory](http://docs.angularjs.org/api/ng/service/$cacheFactory).
|
|
2416
|
+
*
|
|
2417
|
+
* [DSBinaryHeap](/documentation/api/api/DSBinaryHeap) is a priority queue implemented as a Binary Heap.
|
|
2418
|
+
*
|
|
2419
|
+
* Angular-cache is a dependency of [angular-data](/documentation/api/api/angular-data) and must be loaded before
|
|
2420
|
+
* angular-data if you are using angular-data.
|
|
2421
|
+
*/
|
|
2422
|
+
angular.module('angular-data.DSCacheFactory', ['ng', 'angular-data.DSBinaryHeap'])
|
|
2423
|
+
.provider('DSCacheFactory', require('./DSCacheFactory'));
|
|
2424
|
+
|
|
2425
|
+
})(window, window.angular);
|
|
2426
|
+
|
|
2427
|
+
},{"./DSBinaryHeap":1,"./DSCacheFactory":18}],21:[function(require,module,exports){
|
|
2428
|
+
module.exports = {
|
|
2429
|
+
/*!
|
|
2430
|
+
* Stringify a number.
|
|
2431
|
+
*/
|
|
2432
|
+
stringifyNumber: function (number) {
|
|
2433
|
+
if (number && angular.isNumber(number)) {
|
|
2434
|
+
return number.toString();
|
|
2435
|
+
}
|
|
2436
|
+
return number;
|
|
2437
|
+
},
|
|
2438
|
+
|
|
2439
|
+
/*!
|
|
2440
|
+
* Return a hash of the keys in the given collection.
|
|
2441
|
+
*/
|
|
2442
|
+
keySet: function (collection) {
|
|
2443
|
+
var keySet = {}, key;
|
|
2444
|
+
for (key in collection) {
|
|
2445
|
+
if (collection.hasOwnProperty(key)) {
|
|
2446
|
+
keySet[key] = key;
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
return keySet;
|
|
2450
|
+
},
|
|
2451
|
+
|
|
2452
|
+
/*!
|
|
2453
|
+
* Return an array of the keys in the given collection
|
|
2454
|
+
*/
|
|
2455
|
+
keys: function (collection) {
|
|
2456
|
+
var keys = [], key;
|
|
2457
|
+
for (key in collection) {
|
|
2458
|
+
if (collection.hasOwnProperty(key)) {
|
|
2459
|
+
keys.push(key);
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
return keys;
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
|
|
2466
|
+
},{}]},{},[20]);
|