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

Commit a4078fc

Browse files
SekibOmazicIgorMinar
authored andcommitted
perf($cacheFactory): skip LRU bookkeeping for caches with unbound capacity
Fixes #6193 Closes #6226
1 parent 39c82f3 commit a4078fc

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/ng/cacheFactory.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ function $CacheFactoryProvider() {
5959
return caches[cacheId] = {
6060

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

64-
refresh(lruEntry);
65+
refresh(lruEntry);
66+
}
6567

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

7779

7880
get: function(key) {
79-
var lruEntry = lruHash[key];
81+
if (capacity < Number.MAX_VALUE) {
82+
var lruEntry = lruHash[key];
8083

81-
if (!lruEntry) return;
84+
if (!lruEntry) return;
8285

83-
refresh(lruEntry);
86+
refresh(lruEntry);
87+
}
8488

8589
return data[key];
8690
},
8791

8892

8993
remove: function(key) {
90-
var lruEntry = lruHash[key];
94+
if (capacity < Number.MAX_VALUE) {
95+
var lruEntry = lruHash[key];
9196

92-
if (!lruEntry) return;
97+
if (!lruEntry) return;
9398

94-
if (lruEntry == freshEnd) freshEnd = lruEntry.p;
95-
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
96-
link(lruEntry.n,lruEntry.p);
99+
if (lruEntry == freshEnd) freshEnd = lruEntry.p;
100+
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
101+
link(lruEntry.n,lruEntry.p);
102+
103+
delete lruHash[key];
104+
}
97105

98-
delete lruHash[key];
99106
delete data[key];
100107
size--;
101108
},

0 commit comments

Comments
 (0)