#
# var name = "nitlang/nit"
# assert not api.has_cache(name)
-# var repo = api.load_repo(name) # load from GitHub
+# var repo = api.get_repo(name) # load from GitHub
# #assert api.has_cache(name) FIXME bring back this assert
-# repo = api.load_repo(name) # load from cache
+# repo = api.get_repo(name) # load from cache
#
# api.clear_cache
# assert not api.has_cache(name)
fun clear_cache do store.clear
# If no cache data is found for `key` then json is loaded from Github API.
- redef fun load_from_github(key) do
+ redef fun get(key, headers, data) do
if not enable_cache then return super
if store.has_key(key) then
- message(1, "Get {key} (cache)")
+ # print "Get {key} (cache)" # debug
was_error = false
- return deserialize(store.load_object(key).to_json).as(nullable GithubEntity)
+ return deserialize(store.load_object(key).to_json)
end
var obj = super
- if not was_error then
- cache(key, obj.as(not null))
+ if not was_error and obj isa Serializable then
+ cache(key, obj)
end
return obj
end
# Save `json` data in cache under `key`.
- private fun cache(key: String, obj: GithubEntity) do
- message(2, "Cache key {key}")
+ private fun cache(key: String, obj: Serializable) do
+ # print "Cache key {key}" # debug
store.store_object(key, obj.to_json.parse_json.as(JsonObject))
end