mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
issue #374 cap cached frames for cachedframeprocessor to 100
This commit is contained in:
parent
4b50dfdb5b
commit
d08c101b11
@ -1,8 +1,8 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var ns = $.namespace('pskl.model.frame');
|
var ns = $.namespace('pskl.model.frame');
|
||||||
|
|
||||||
// 10 * 60 * 1000 = 10 minutes
|
// Maximum number of cache entries
|
||||||
var DEFAULT_CLEAR_INTERVAL = 10 * 60 * 1000;
|
var MAX_CACHE_ENTRIES = 100;
|
||||||
|
|
||||||
var DEFAULT_FRAME_PROCESSOR = function (frame) {
|
var DEFAULT_FRAME_PROCESSOR = function (frame) {
|
||||||
return pskl.utils.FrameUtils.toImage(frame);
|
return pskl.utils.FrameUtils.toImage(frame);
|
||||||
@ -12,14 +12,16 @@
|
|||||||
|
|
||||||
var DEFAULT_NAMESPACE = '__cache_default__';
|
var DEFAULT_NAMESPACE = '__cache_default__';
|
||||||
|
|
||||||
ns.CachedFrameProcessor = function (cacheResetInterval) {
|
ns.CachedFrameProcessor = function () {
|
||||||
|
// Cache object.
|
||||||
this.cache_ = {};
|
this.cache_ = {};
|
||||||
this.cacheResetInterval = cacheResetInterval || DEFAULT_CLEAR_INTERVAL;
|
|
||||||
|
// Array of [namespace, key] for each cached frame.
|
||||||
|
this.cacheQueue_ = [];
|
||||||
|
|
||||||
this.frameProcessor = DEFAULT_FRAME_PROCESSOR;
|
this.frameProcessor = DEFAULT_FRAME_PROCESSOR;
|
||||||
this.outputCloner = DEFAULT_OUTPUT_CLONER;
|
this.outputCloner = DEFAULT_OUTPUT_CLONER;
|
||||||
this.defaultNamespace = DEFAULT_NAMESPACE;
|
this.defaultNamespace = DEFAULT_NAMESPACE;
|
||||||
|
|
||||||
window.setInterval(this.clear.bind(this), this.cacheResetInterval);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CachedFrameProcessor.prototype.clear = function () {
|
ns.CachedFrameProcessor.prototype.clear = function () {
|
||||||
@ -69,6 +71,11 @@
|
|||||||
} else {
|
} else {
|
||||||
processedFrame = this.frameProcessor(frame);
|
processedFrame = this.frameProcessor(frame);
|
||||||
cache[cacheKey] = processedFrame;
|
cache[cacheKey] = processedFrame;
|
||||||
|
this.cacheQueue_.unshift([namespace, cacheKey]);
|
||||||
|
if (this.cacheQueue_.length > MAX_CACHE_ENTRIES) {
|
||||||
|
var oldestItem = this.cacheQueue_.pop();
|
||||||
|
this.cache_[oldestItem[0]][oldestItem[1]] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return processedFrame;
|
return processedFrame;
|
||||||
|
Loading…
Reference in New Issue
Block a user