diff --git a/WebKit/scripts/helper/Cache.js b/WebKit/scripts/helper/Cache.js new file mode 100644 index 0000000..e63dae4 --- /dev/null +++ b/WebKit/scripts/helper/Cache.js @@ -0,0 +1,49 @@ +define([ + "helper/Paths", + "lib/URI" +], + +function(Paths, URI) { + + function Cache() { + + this.timeout = 2 * 60 * 1000; + this.before_id = null; + + this.followings = {}; + + var _this = this; + this.intervall = setInterval(function() { _this.getAllFollowings(); }, this.timeout); + + this.getAllFollowings(); + } + + Cache.prototype.getAllFollowings = function() { + + var _this = this; + + var callback = function(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.before_id = following.id; + _this.followings[following.entity] = following; + } + } + + var url = URI(Paths.mkApiRootPath("/followings")); + if (this.before_id) { + url.addSearch("before_id", this.before_id); + } + + Paths.getURL(url, "GET", callback); + } + + return Cache; + +}); \ No newline at end of file