Browse Source

Make the view history cache size configurable during initialization

Tim van der Meij 10 years ago
parent
commit
55870788e5
  1. 7
      web/view_history.js

7
web/view_history.js

@ -18,7 +18,7 @@
'use strict'; '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 * 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. * - GENERIC or CHROME - uses localStorage, if it is available.
*/ */
var ViewHistory = (function ViewHistoryClosure() { var ViewHistory = (function ViewHistoryClosure() {
function ViewHistory(fingerprint) { function ViewHistory(fingerprint, cacheSize) {
this.fingerprint = fingerprint; this.fingerprint = fingerprint;
this.cacheSize = cacheSize || DEFAULT_VIEW_HISTORY_CACHE_SIZE;
this.isInitializedPromiseResolved = false; this.isInitializedPromiseResolved = false;
this.initializedPromise = this.initializedPromise =
this._readFromStorage().then(function (databaseStr) { this._readFromStorage().then(function (databaseStr) {
@ -41,7 +42,7 @@ var ViewHistory = (function ViewHistoryClosure() {
if (!('files' in database)) { if (!('files' in database)) {
database.files = []; database.files = [];
} }
if (database.files.length >= VIEW_HISTORY_MEMORY) { if (database.files.length >= this.cacheSize) {
database.files.shift(); database.files.shift();
} }
var index; var index;

Loading…
Cancel
Save