1 |
|
2 | var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
3 |
|
4 | module.exports = function(providerParams) {
|
5 | var Cache, CachedResourceManager, buildCachedResourceClass;
|
6 | buildCachedResourceClass = require('./build_cached_resource_class');
|
7 | Cache = require('./cache')(providerParams);
|
8 | return CachedResourceManager = (function() {
|
9 | function CachedResourceManager($resource, $timeout, $q) {
|
10 | this.byKey = {};
|
11 | this.build = angular.bind(this, buildCachedResourceClass, $resource, $timeout, $q, providerParams);
|
12 | }
|
13 |
|
14 | CachedResourceManager.prototype.keys = function() {
|
15 | return Object.keys(this.byKey);
|
16 | };
|
17 |
|
18 | CachedResourceManager.prototype.add = function() {
|
19 | var CachedResource, args;
|
20 | args = Array.prototype.slice.call(arguments);
|
21 | CachedResource = this.build(args);
|
22 | this.byKey[CachedResource.$key] = CachedResource;
|
23 | CachedResource.$writes.flush();
|
24 | return CachedResource;
|
25 | };
|
26 |
|
27 | CachedResourceManager.prototype.flushQueues = function() {
|
28 | var CachedResource, key, _ref, _results;
|
29 | _ref = this.byKey;
|
30 | _results = [];
|
31 | for (key in _ref) {
|
32 | CachedResource = _ref[key];
|
33 | _results.push(CachedResource.$writes.flush());
|
34 | }
|
35 | return _results;
|
36 | };
|
37 |
|
38 | CachedResourceManager.prototype.clearCache = function(_arg) {
|
39 | var CachedResource, clearPendingWrites, exceptFor, key, _ref, _ref1, _results;
|
40 | _ref = _arg != null ? _arg : {}, exceptFor = _ref.exceptFor, clearPendingWrites = _ref.clearPendingWrites;
|
41 | if (exceptFor == null) {
|
42 | exceptFor = [];
|
43 | }
|
44 | _ref1 = this.byKey;
|
45 | _results = [];
|
46 | for (key in _ref1) {
|
47 | CachedResource = _ref1[key];
|
48 | if (__indexOf.call(exceptFor, key) < 0) {
|
49 | _results.push(CachedResource.$clearCache({
|
50 | clearPendingWrites: clearPendingWrites
|
51 | }));
|
52 | }
|
53 | }
|
54 | return _results;
|
55 | };
|
56 |
|
57 | CachedResourceManager.prototype.clearUndefined = function() {
|
58 | return Cache.clear({
|
59 | exceptFor: this.keys()
|
60 | });
|
61 | };
|
62 |
|
63 | return CachedResourceManager;
|
64 |
|
65 | })();
|
66 | };
|