class

Halite::Cache

Inherits Halite::Feature / Reference / Object

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 is true

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 time
  • X-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"}}

Constants

DEFAULT_PATH = "/tmp/halite/cache/"

Constructors

new

return a new Cache instance

Accepts argument:

  • debug: Bool
  • path: String
  • expires: (Int32 | Time::Span)?
Source

Instance methods

debug
Source
expires
Source
file
Source
intercept(chain)
Source
path
Source