{"size": 1607, "ext": "js", "max_stars_repo_path": "WebKit/scripts/helper/Cache.js", "max_stars_repo_name": "jeena/Bungloo", "max_stars_repo_stars_event_min_datetime": "2015-06-01T09:20:48.000Z", "max_stars_repo_stars_event_max_datetime": "2015-06-01T09:20:48.000Z", "max_issues_repo_path": "WebKit/scripts/helper/Cache.js", "max_issues_repo_name": "jeena/Bungloo", "max_issues_repo_issues_event_min_datetime": "2019-11-28T08:57:04.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-28T08:57:04.000Z", "max_forks_repo_path": "WebKit/scripts/helper/Cache.js", "max_forks_repo_name": "jeena/Bungloo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 25.9193548387, "max_line_length": 79, "alphanum_fraction": 0.5880522713}
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/APICalls").mkApiRootPath("/followings"));
        if (this.followings_before_id) {
            url.addSearch("before_id", this.followings_before_id);
        }

        require("helper/APICalls").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;

});