Skip to content

Commit d7045ad

Browse files
author
OpenShift Bot
authored
Merge pull request openshift#564 from jwforres/fix-isi-cache-bust
Merged by openshift-bot
2 parents e9b0811 + 53a3c59 commit d7045ad

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

app/scripts/services/data.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ angular.module('openshiftConsole')
8787
// 25 is a reasonable number to keep at least one or two projects worth of data in cache
8888
number: 25
8989
});
90+
this._immutableDataCache = $cacheFactory('immutableDataCache', {
91+
// 50 is a reasonable number for the immutable resources that are stored per resource instead of grouped by type
92+
number: 50
93+
});
9094
this._watchOptionsMap = {};
9195
this._watchWebsocketsMap = {};
9296
this._watchPollTimeoutsMap = {};
@@ -329,13 +333,13 @@ angular.module('openshiftConsole')
329333

330334
var deferred = $q.defer();
331335

332-
var existingData = this._data(key);
336+
var existingImmutableData = this._immutableData(key);
333337

334338
// special case, if we have an immutable item, we can return it immediately
335-
if (this._hasImmutable(resource, existingData, name)) {
339+
if (this._hasImmutable(resource, existingImmutableData, name)) {
336340
$timeout(function() {
337341
// we can be guaranteed this wont change on us, just send what we have in existingData
338-
deferred.resolve(existingData.by('metadata.name')[name]);
342+
deferred.resolve(existingImmutableData.by('metadata.name')[name]);
339343
}, 0);
340344
}
341345
else {
@@ -348,11 +352,11 @@ angular.module('openshiftConsole')
348352
}, opts.http || {}))
349353
.success(function(data, status, headerFunc, config, statusText) {
350354
if (self._isImmutable(resource)) {
351-
if (!existingData) {
352-
self._data(key, [data]);
355+
if (!existingImmutableData) {
356+
self._immutableData(key, [data]);
353357
}
354358
else {
355-
existingData.update(data, "ADDED");
359+
existingImmutableData.update(data, "ADDED");
356360
}
357361
}
358362
deferred.resolve(data);
@@ -650,7 +654,7 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
650654
var key = this._uniqueKey(resource, null, context, _.get(opts, 'http.params'));
651655

652656
if (objectCallback && objectName) {
653-
var objectKey = this._uniqueKey(resource, objectName, context, _.get(opts, 'http.params'));
657+
var objectKey = this._uniqueKey(resource, objectName, context, _.get(opts, 'http.params'));
654658
var objCallbacks = this._watchObjectCallbacks(objectKey);
655659
objCallbacks.remove(objectCallback);
656660
}
@@ -740,6 +744,13 @@ DataService.prototype.createStream = function(resource, name, context, opts, isR
740744
this._dataCache.get(key);
741745
};
742746

747+
// uses $cacheFactory to impl LRU cache
748+
DataService.prototype._immutableData = function(key, data) {
749+
return data ?
750+
this._immutableDataCache.put(key, new Data(data)) :
751+
this._immutableDataCache.get(key);
752+
};
753+
743754
DataService.prototype._isCached = function(key) {
744755
return this._watchInFlight(key) &&
745756
this._resourceVersion(key) &&

dist/scripts/scripts.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ c[h] || (c[h] = {}), "DELETED" === d ? delete c[h][i] :c[h][i] = a;
888888
function m() {
889889
this._listCallbacksMap = {}, this._watchCallbacksMap = {}, this._watchObjectCallbacksMap = {}, this._watchOperationMap = {}, this._listOperationMap = {}, this._resourceVersionMap = {}, this._dataCache = a("dataCache", {
890890
number:25
891+
}), this._immutableDataCache = a("immutableDataCache", {
892+
number:50
891893
}), this._watchOptionsMap = {}, this._watchWebsocketsMap = {}, this._watchPollTimeoutsMap = {}, this._websocketEventsMap = {};
892894
var b = this;
893895
d.$on("$routeChangeStart", function(a, c, d) {
@@ -1040,7 +1042,7 @@ a = g.toResourceGroupVersion(a), f = f || {};
10401042
var i = this._uniqueKey(a, c, d, _.get(f, "http.params"));
10411043
!!f.force;
10421044
delete f.force;
1043-
var k = e.defer(), l = this._data(i);
1045+
var k = e.defer(), l = this._immutableData(i);
10441046
if (this._hasImmutable(a, l, c)) j(function() {
10451047
k.resolve(l.by("metadata.name")[c]);
10461048
}, 0); else {
@@ -1051,7 +1053,7 @@ method:"GET",
10511053
auth:{},
10521054
url:m._urlForResource(a, c, d, !1, e)
10531055
}, f.http || {})).success(function(b, c, d, e, f) {
1054-
m._isImmutable(a) && (l ? l.update(b, "ADDED") :m._data(i, [ b ])), k.resolve(b);
1056+
m._isImmutable(a) && (l ? l.update(b, "ADDED") :m._immutableData(i, [ b ])), k.resolve(b);
10551057
}).error(function(b, d, e, g) {
10561058
if (f.errorNotification !== !1) {
10571059
var i = "Failed to get " + a + "/" + c;
@@ -1212,6 +1214,8 @@ return b || b === !1 ? void (this._listOperationMap[a] = b) :this._listOperation
12121214
return b ? void (this._resourceVersionMap[a] = b) :this._resourceVersionMap[a];
12131215
}, m.prototype._data = function(a, b) {
12141216
return b ? this._dataCache.put(a, new k(b)) :this._dataCache.get(a);
1217+
}, m.prototype._immutableData = function(a, b) {
1218+
return b ? this._immutableDataCache.put(a, new k(b)) :this._immutableDataCache.get(a);
12151219
}, m.prototype._isCached = function(a) {
12161220
return this._watchInFlight(a) && this._resourceVersion(a) && !!this._data(a);
12171221
}, m.prototype._watchOptions = function(a, b) {

0 commit comments

Comments
 (0)