Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
perf($cacheFactory): skip LRU bookkeeping for caches with unbound cap…
Browse files Browse the repository at this point in the history
…acity

Fixes #6193
Closes #6226
  • Loading branch information
SekibOmazic authored and IgorMinar committed Feb 22, 2014
1 parent 39c82f3 commit a4078fc
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/ng/cacheFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function $CacheFactoryProvider() {
return caches[cacheId] = {

put: function(key, value) {
var lruEntry = lruHash[key] || (lruHash[key] = {key: key});
if (capacity < Number.MAX_VALUE) {
var lruEntry = lruHash[key] || (lruHash[key] = {key: key});

refresh(lruEntry);
refresh(lruEntry);
}

if (isUndefined(value)) return;
if (!(key in data)) size++;
Expand All @@ -76,26 +78,31 @@ function $CacheFactoryProvider() {


get: function(key) {
var lruEntry = lruHash[key];
if (capacity < Number.MAX_VALUE) {
var lruEntry = lruHash[key];

if (!lruEntry) return;
if (!lruEntry) return;

refresh(lruEntry);
refresh(lruEntry);
}

return data[key];
},


remove: function(key) {
var lruEntry = lruHash[key];
if (capacity < Number.MAX_VALUE) {
var lruEntry = lruHash[key];

if (!lruEntry) return;
if (!lruEntry) return;

if (lruEntry == freshEnd) freshEnd = lruEntry.p;
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
link(lruEntry.n,lruEntry.p);
if (lruEntry == freshEnd) freshEnd = lruEntry.p;
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
link(lruEntry.n,lruEntry.p);

delete lruHash[key];
}

delete lruHash[key];
delete data[key];
size--;
},
Expand Down

0 comments on commit a4078fc

Please sign in to comment.