File: //usr/share/nodejs/turbolinks/src/turbolinks/snapshot_cache.js
// Generated by CoffeeScript 1.12.8
(function() {
Turbolinks.SnapshotCache = (function() {
var keyForLocation;
function SnapshotCache(size) {
this.size = size;
this.keys = [];
this.snapshots = {};
}
SnapshotCache.prototype.has = function(location) {
var key;
key = keyForLocation(location);
return key in this.snapshots;
};
SnapshotCache.prototype.get = function(location) {
var snapshot;
if (!this.has(location)) {
return;
}
snapshot = this.read(location);
this.touch(location);
return snapshot;
};
SnapshotCache.prototype.put = function(location, snapshot) {
this.write(location, snapshot);
this.touch(location);
return snapshot;
};
SnapshotCache.prototype.read = function(location) {
var key;
key = keyForLocation(location);
return this.snapshots[key];
};
SnapshotCache.prototype.write = function(location, snapshot) {
var key;
key = keyForLocation(location);
return this.snapshots[key] = snapshot;
};
SnapshotCache.prototype.touch = function(location) {
var index, key;
key = keyForLocation(location);
index = this.keys.indexOf(key);
if (index > -1) {
this.keys.splice(index, 1);
}
this.keys.unshift(key);
return this.trim();
};
SnapshotCache.prototype.trim = function() {
var i, key, len, ref, results;
ref = this.keys.splice(this.size);
results = [];
for (i = 0, len = ref.length; i < len; i++) {
key = ref[i];
results.push(delete this.snapshots[key]);
}
return results;
};
keyForLocation = function(location) {
return Turbolinks.Location.wrap(location).toCacheKey();
};
return SnapshotCache;
})();
}).call(this);