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

refactor($cacheFactory): cache inefficient when no capacity #6226

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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