Cachex: Make caching provider switchable at runtime.

Defaults to Cachex.
This commit is contained in:
lain 2020-12-18 17:44:46 +01:00
commit 713612c377
20 changed files with 92 additions and 59 deletions

View file

@ -8,6 +8,8 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do
@behaviour Plug
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
@impl true
def init(opts), do: opts
@ -25,7 +27,7 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do
def call(conn, _), do: conn
def process_request(conn, key) do
case Cachex.get(:idempotency_cache, key) do
case @cachex.get(:idempotency_cache, key) do
{:ok, nil} ->
cache_resposnse(conn, key)
@ -43,7 +45,7 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do
content_type = get_content_type(conn)
record = {request_id, content_type, conn.status, conn.resp_body}
{:ok, _} = Cachex.put(:idempotency_cache, key, record)
{:ok, _} = @cachex.put(:idempotency_cache, key, record)
conn
|> put_resp_header("idempotency-key", key)