cache api clients

This commit is contained in:
Albert Yi
2018-09-10 17:28:18 -07:00
parent e0e85a3139
commit 266c7c0d5b
11 changed files with 99 additions and 64 deletions

View File

@@ -0,0 +1,11 @@
module HttpartyCache
extend self
def get(url, headers: {}, params: {}, base_uri: nil, format: :html, expiry: 60)
Cache.get("cachedget:#{Cache.hash(url)}", expiry) do
resp = HTTParty.get(url, Danbooru.config.httparty_options.deep_merge(query: params, headers: headers, base_uri: base_uri, format: format))
body = resp.body.force_encoding("utf-8")
[body, resp.code]
end
end
end