Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oldhammade/teslacacher
A caching middleware for Tesla, backed by Redix.
https://github.com/oldhammade/teslacacher
elixir elixir-lang elixir-library tesla
Last synced: 19 days ago
JSON representation
A caching middleware for Tesla, backed by Redix.
- Host: GitHub
- URL: https://github.com/oldhammade/teslacacher
- Owner: OldhamMade
- License: other
- Created: 2020-10-30T15:07:29.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-09-10T10:00:40.000Z (2 months ago)
- Last Synced: 2024-10-15T17:16:45.761Z (about 1 month ago)
- Topics: elixir, elixir-lang, elixir-library, tesla
- Language: Elixir
- Homepage: https://hex.pm/packages/tesla_cacher
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TeslaCacher
[![Build Status](https://travis-ci.org/OldhamMade/TeslaCacher.svg?branch=main)][TravisCI]
[![Module Version](https://img.shields.io/hexpm/v/tesla_cacher.svg)](https://hex.pm/packages/tesla_cacher)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/tesla_cacher)
[![Total Download](https://img.shields.io/hexpm/dt/tesla_cacher.svg)](https://hex.pm/packages/tesla_cacher)
[![License](https://img.shields.io/hexpm/l/tesla_cacher.svg)](https://hex.pm/packages/tesla_cacher)
[![Last Updated](https://img.shields.io/github/last-commit/OldhamMade/TeslaCacher.svg)](https://github.com/OldhamMade/TeslaCacher/commits/master)TeslaCacher is a Basic Cache Middleware for Tesla backed by
[Redix][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][Teslacache], which is backed by
[Cachex][Cachex].## Installation
Add `tesla_cacher` to your list of dependencies in `mix.exs`:
```elixir
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:```elixir
defmodule MyClient do
use Teslaplug 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`.[Redix]: https://hex.pm/packages/redix
[Teslacache]: https://hex.pm/packages/tesla_cache
[Cachex]: https://hex.pm/packages/cachex
[TravisCI]: https://travis-ci.org/OldhamMade/TeslaCacher