added Cache

This commit is contained in:
Jeena Paradies 2012-12-11 00:46:08 +01:00
parent dacd2ee019
commit c3d1ce7d24
8 changed files with 280 additions and 105 deletions

View file

@ -1,28 +1,23 @@
define([
"helper/Paths",
"lib/URI"
"lib/URI",
"helper/CacheStorage"
],
function(Paths, URI) {
function(Paths, URI, CacheStorage) {
function Cache() {
var Cache = {};
this.timeout = 2 * 60 * 1000;
this.before_id = null;
var timeout = 2 * 60 * 1000;
var followings_before_id = null;
this.followings = {};
var _this = this;
this.intervall = setInterval(function() { _this.getAllFollowings(); }, this.timeout);
Cache.followings = new CacheStorage("followings");
Cache.profiles = new CacheStorage("profiles");
Cache.profile_urls = new CacheStorage("profile_urls");
this.getAllFollowings();
}
Cache.prototype.getAllFollowings = function() {
var _this = this;
var callback = function(resp) {
Cache.getFollowings = function() {
function callback(resp) {
var fs = JSON.parse(resp.responseText)
@ -31,18 +26,24 @@ function(Paths, URI) {
for (var i = 0; i < fs.length; i++) {
var following = fs[i];
_this.before_id = following.id;
_this.followings[following.entity] = following;
followings_before_id = following.id;
Cache.followings.setItem(following.entity, following)
Cache.profiles.setItem(following.entity, following);
}
}
var url = URI(Paths.mkApiRootPath("/followings"));
if (this.before_id) {
url.addSearch("before_id", this.before_id);
var u = Paths.mkApiRootPath("/followings");
var url = URI(u);
if (followings_before_id) {
url.addSearch("before_id", followings_before_id);
}
Paths.getURL(url, "GET", callback);
}
// setTimeout(function(){ Cache.getAllFollowings() }, timeout);
return Cache;