Skip to content

Commit

Permalink
Added method to clear caches
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Oct 26, 2016
1 parent fefb26a commit 418ba71
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions dev/raphael.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,21 +833,20 @@

var CACHE = R.CACHE = {};

function cacher(name, f, scope, postprocessor) {
function cacher(f, scope, postprocessor) {

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

if (cache[has](args)) {

if (count[count.length - 1] !== args) {
repush(count, args);
}

return postprocessor ? postprocessor(cache[args]) : cache[args];
}

count.length >= 1e3 && delete cache[count.shift()];
count.push(args);
var cached = cache[args] = f[apply](scope, arg);
Expand All @@ -857,11 +856,24 @@
var cache = newf.cache = {},
count = newf.count = [];

newf.clear = function () {
cache = newf.cache = {};
count = newf.count = [];
};

CACHE[name] = newf;

return newf;
}

R.clearCaches = function () {
for (var key in CACHE) {
if (!CACHE.hasOwnProperty(key)) continue;

CACHE[key].clear();
}
};

var preload = R._preload = function (src, f) {
var img = g.doc.createElement("img");
img.style.cssText = "position:absolute;left:-9999em;top:-9999em";
Expand Down

0 comments on commit 418ba71

Please sign in to comment.