Make the view history cache size configurable during initialization

This commit is contained in:
Tim van der Meij 2015-11-02 14:56:50 +01:00
parent 7681def0de
commit 55870788e5

View File

@ -18,7 +18,7 @@
'use strict';
var VIEW_HISTORY_MEMORY = 20;
var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
/**
* View History - This is a utility for saving various view parameters for
@ -30,8 +30,9 @@ var VIEW_HISTORY_MEMORY = 20;
* - GENERIC or CHROME - uses localStorage, if it is available.
*/
var ViewHistory = (function ViewHistoryClosure() {
function ViewHistory(fingerprint) {
function ViewHistory(fingerprint, cacheSize) {
this.fingerprint = fingerprint;
this.cacheSize = cacheSize || DEFAULT_VIEW_HISTORY_CACHE_SIZE;
this.isInitializedPromiseResolved = false;
this.initializedPromise =
this._readFromStorage().then(function (databaseStr) {
@ -41,7 +42,7 @@ var ViewHistory = (function ViewHistoryClosure() {
if (!('files' in database)) {
database.files = [];
}
if (database.files.length >= VIEW_HISTORY_MEMORY) {
if (database.files.length >= this.cacheSize) {
database.files.shift();
}
var index;