UNPKG

1.71 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.8.0
2module.exports = function(providerParams) {
3 var $log, Cache, ResourceCacheEntry;
4 $log = providerParams.$log;
5 Cache = require('./cache')(providerParams);
6 return ResourceCacheEntry = (function() {
7 ResourceCacheEntry.prototype.defaultValue = {};
8
9 ResourceCacheEntry.prototype.cacheKeyPrefix = function() {
10 return this.key;
11 };
12
13 ResourceCacheEntry.prototype.fullCacheKey = function() {
14 return this.cacheKeyPrefix() + this.cacheKeyParams;
15 };
16
17 function ResourceCacheEntry(key, params) {
18 var param, paramKeys;
19 this.key = key;
20 paramKeys = angular.isObject(params) ? Object.keys(params).sort() : [];
21 if (paramKeys.length) {
22 this.cacheKeyParams = '?' + ((function() {
23 var _i, _len, _results;
24 _results = [];
25 for (_i = 0, _len = paramKeys.length; _i < _len; _i++) {
26 param = paramKeys[_i];
27 _results.push("" + param + "=" + params[param]);
28 }
29 return _results;
30 })()).join('&');
31 } else {
32 this.cacheKeyParams = '';
33 }
34 }
35
36 ResourceCacheEntry.prototype.load = function() {
37 var _ref;
38 _ref = Cache.getItem(this.fullCacheKey(), this.defaultValue), this.value = _ref.value, this.dirty = _ref.dirty;
39 return this;
40 };
41
42 ResourceCacheEntry.prototype.set = function(value, dirty) {
43 this.value = value;
44 this.dirty = dirty;
45 return this._update();
46 };
47
48 ResourceCacheEntry.prototype._update = function() {
49 return Cache.setItem(this.fullCacheKey(), {
50 value: this.value,
51 dirty: this.dirty
52 });
53 };
54
55 return ResourceCacheEntry;
56
57 })();
58};