You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Halite.cache.get "https://httpbin.ogr/get"Halite.cache(directory:"cache", expired:1.hour).get "https://httpbin.ogr/get"# Loads the content of "cache/get.txt" Halite.cache(file:"get.txt").get "https://httpbin.ogr/get"
Use it with instance client:
client =Halite::Client.new do |options|
options.cache =trueend
client =Halite::Client.new do |options|
options.cache(directory:"cache", expired:1.hour)
end
client.get "https://httpbin.ogr/get"
This request will store into cache path: "cache/{cache_key}" with two files:
It supports load cache from file, just passes file argument, Cache will load the content of file and return to Halite::Response no matter request whatever is.
Better to debug and improve the speed for developing third party API.
Logic
Cache key
generate algorithm
md5(verb + url + body)
Cache response
Store response into two files:
metadata
: Stored status_code and headers in JSON format.body
: Original body of response, so it can be binary data.metadata
JSON structure:Expires time
Supports
Int32
,Time::Span
is enough.Examples
Use it with single call
Use it with instance client:
This request will store into cache path: "cache/{cache_key}" with two files:
metadata.json:
{cache_key}.cache
Load from file
It supports load cache from file, just passes
file
argument, Cache will load the content of file and return toHalite::Response
no matter request whatever is.PR
#35
The text was updated successfully, but these errors were encountered: