TeslaCacher is a Basic Cache Middleware for Tesla backed by
Redix. It will cache GET requests for N milliseconds, if
defined, otherwise for the lifetime of the Redis session. Requests
other than GET are NOT cached.
Not to be confused with TeslaCache, which is backed by Cachex.
Add tesla_cacher to your list of dependencies in mix.exs:
def deps do
[
{:tesla_cacher, "~> 0.1.0"}
]
endTeslaCacher does not manage Redix for you, you must start and monitor it yourself and provide the details to the plugin:
defmodule MyClient do
use Tesla
plug Tesla.Middleware.Cacher,
redix: :redix,
expiry: :timer.seconds(2),
timeout: :timer.seconds(5),
prefix: :tesla_cacher
endredix -- [required] the connection handle for redix. Can be an
atom or a PID.
expiry -- [optional] (integer or :infinity) the expire time, in
milliseconds. Default is :infinity.
timeout -- [optional] (integer or :infinity) request timeout, in
milliseconds. Default is 5000.
prefix -- [optional] (atom or string) a prefix to be used for redis
keys. | (pipe) is used as a separator to avoid lookup conflicts with
common redis key schemes. Default is tesla_cacher.