tallgrass/client/cache

Basic request caching based on Erlang Term Storage (ETS).

Types

A ready-to-use cache can be initialized by using the new function.

Example

let assert Ok(cache) = cache.new("my-unique-name")
let client = client.new() |> with_cache(cache)
client |> pokemon.fetch()
pub type Cache {
  Cache(Set(String, String))
  NoCache
}

Constructors

  • Cache(Set(String, String))
  • NoCache

Specifies how often the cache should be expired in seconds, minutes, or hours.

pub type CacheExpiry {
  Seconds(Int)
  Minutes(Int)
  Hours(Int)
}

Constructors

  • Seconds(Int)
  • Minutes(Int)
  • Hours(Int)

Functions

pub fn new(
  name: String,
  expiry: CacheExpiry,
) -> Result(Cache, Error)

Initializes a cache that can be passed to client.with_cache() If multiple caches are initialized, the name param should be unique in order to avoid ETS runtime errors.

Search Document