Skip to content

Commit 85c9b84

Browse files
committed
Added method to clear caches
1 parent cd9321a commit 85c9b84

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dev/raphael.core.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,21 +833,20 @@
833833

834834
var CACHE = R.CACHE = {};
835835

836-
function cacher(name, f, scope, postprocessor) {
836+
function cacher(f, scope, postprocessor) {
837837

838838
function newf() {
839839
var arg = Array.prototype.slice.call(arguments, 0),
840840
args = arg.join("\u2400");
841841

842842
if (cache[has](args)) {
843-
844843
if (count[count.length - 1] !== args) {
845844
repush(count, args);
846845
}
847-
846+
848847
return postprocessor ? postprocessor(cache[args]) : cache[args];
849848
}
850-
849+
851850
count.length >= 1e3 && delete cache[count.shift()];
852851
count.push(args);
853852
var cached = cache[args] = f[apply](scope, arg);
@@ -857,11 +856,24 @@
857856
var cache = newf.cache = {},
858857
count = newf.count = [];
859858

859+
newf.clear = function () {
860+
cache = newf.cache = {};
861+
count = newf.count = [];
862+
};
863+
860864
CACHE[name] = newf;
861865

862866
return newf;
863867
}
864868

869+
R.clearCaches = function () {
870+
for (var key in CACHE) {
871+
if (!CACHE.hasOwnProperty(key)) continue;
872+
873+
CACHE[key].clear();
874+
}
875+
};
876+
865877
var preload = R._preload = function (src, f) {
866878
var img = g.doc.createElement("img");
867879
img.style.cssText = "position:absolute;left:-9999em;top:-9999em";

0 commit comments

Comments
 (0)