class Halite::Cache
- Halite::Cache
- Halite::Feature
- Reference
- Object
Overview
Cache feature use for caching HTTP response to local storage to speed up in developing stage.
It has the following options:
#file
: Load cache from file. it conflict with#path
and#expires
.#path
: The path of cache, default is "/tmp/halite/cache/"#expires
: The expires time of cache, default is never expires.#debug
: The debug mode of cache, default istrue
With debug mode, cached response it always included some headers information:
X-Halite-Cached-From
: Cache source (cache or file)X-Halite-Cached-Key
: Cache key with verb, uri and body (return with cache, not#file
passed)X-Halite-Cached-At
: Cache created timeX-Halite-Cached-Expires-At
: Cache expired time (return with cache, not#file
passed)
Halite.use("cache").get "http://httpbin.org/anything" # request a HTTP
r = Halite.use("cache").get "http://httpbin.org/anything" # request from local storage
r.headers # => {..., "X-Halite-Cached-At" => "2018-08-30 10:41:14 UTC", "X-Halite-Cached-By" => "Halite", "X-Halite-Cached-Expires-At" => "2018-08-30 10:41:19 UTC", "X-Halite-Cached-Key" => "2bb155e6c8c47627da3d91834eb4249a"}}
Defined in:
halite/features/cache.crConstant Summary
-
DEFAULT_PATH =
"/tmp/halite/cache/"
Constructors
-
.new(**options)
return a new Cache instance
Instance Method Summary
Instance methods inherited from class Halite::Feature
intercept(chain : Halite::Feature::Chain) : Halite::Feature::Chain
intercept,
request(request : Halite::Request) : Halite::Request
request,
response(response : Halite::Response) : Halite::Response
response
Constructor methods inherited from class Halite::Feature
new(**options)
new
Constructor Detail
def self.new(**options)
#
return a new Cache instance
Accepts argument:
- debug:
Bool
- path:
String
- expires:
(Int32 | Time::Span)?