This repository has been archived on 2025-08-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Bungloo/WebKit/scripts/helper/Cache.js
2012-12-18 23:03:19 +01:00

62 lines
No EOL
1.6 KiB
JavaScript

define([
"lib/URI",
"helper/CacheStorage",
"require"
],
function(URI, CacheStorage, require) {
function Cache() {
this.timeout = 2 * 60 * 1000;
this.followings_before_id = null;
this.intervall = null;
//this.clear()
this.followings = new CacheStorage("followings");
this.profiles = new CacheStorage("profiles");
this.profile_urls = new CacheStorage("profile_urls");
}
Cache.prototype.clear = function() {
localStorage.clear();
}
Cache.prototype.getFollowings = function() {
var _this = this;
function callback(resp) {
var fs = JSON.parse(resp.responseText)
if (fs.length < 1) return;
for (var i = 0; i < fs.length; i++) {
var following = fs[i];
this.followings_before_id = following.id;
_this.followings.setItem(following.entity, following)
_this.profiles.setItem(following.entity, following);
}
}
var url = URI(require("helper/Paths").mkApiRootPath("/followings"));
if (this.followings_before_id) {
url.addSearch("before_id", this.followings_before_id);
}
require("helper/Paths").getURL(url, "GET", callback);
}
Cache.prototype.periodicallyGetFollowings = function() {
this.getFollowings();
this.intervall = setInterval(this.getFollowings, this.timeout);
}
Cache.prototype.stopGettingFollowings = function() {
clearTimeout(this.intervall);
}
return Cache;
});