Skip to content

OldhamMade/TeslaCacher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TeslaCacher

Build Status Module Version Hex Docs Total Download License Last Updated

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.

Installation

Add tesla_cacher to your list of dependencies in mix.exs:

def deps do
  [
    {:tesla_cacher, "~> 0.1.0"}
  ]
end

Usage

TeslaCacher 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
end

Options

redix -- [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.