diff options
author | lain <lain@soykaf.club> | 2020-12-21 11:42:53 +0100 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-12-21 11:42:53 +0100 |
commit | ee81a94ab2631e994f7d963d74fadf1ce0704837 (patch) | |
tree | 96aa1922696c8084570031701708e47ab9c7d611 | |
parent | 95a9bdfc374a013be47e74b25bdba5d91f51948b (diff) | |
download | pleroma-ee81a94ab2631e994f7d963d74fadf1ce0704837.tar.gz |
Caching: Add caching behavior, add null implementation.
-rw-r--r-- | lib/pleroma/caching.ex | 19 | ||||
-rw-r--r-- | test/support/null_cache.ex | 8 |
2 files changed, 24 insertions, 3 deletions
diff --git a/lib/pleroma/caching.ex b/lib/pleroma/caching.ex new file mode 100644 index 000000000..766d12d1b --- /dev/null +++ b/lib/pleroma/caching.ex @@ -0,0 +1,19 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Caching do + @callback get!(Cachex.cache(), any()) :: any() + @callback get(Cachex.cache(), any()) :: {atom(), any()} + @callback put(Cachex.cache(), any(), any(), Keyword.t()) :: {Cachex.status(), boolean()} + @callback put(Cachex.cache(), any(), any()) :: {Cachex.status(), boolean()} + @callback fetch!(Cachex.cache(), any(), function() | nil) :: any() + # @callback del(Cachex.cache(), any(), Keyword.t()) :: {Cachex.status(), boolean()} + @callback del(Cachex.cache(), any()) :: {Cachex.status(), boolean()} + @callback stream!(Cachex.cache(), any()) :: Enumerable.t() + @callback expire_at(Cachex.cache(), binary(), number()) :: {Cachex.status(), boolean()} + @callback exists?(Cachex.cache(), any()) :: {Cachex.status(), boolean()} + @callback execute!(Cachex.cache(), function()) :: any() + @callback get_and_update(Cachex.cache(), any(), function()) :: + {:commit | :ignore, any()} +end diff --git a/test/support/null_cache.ex b/test/support/null_cache.ex index 72e7c996a..c63df6a39 100644 --- a/test/support/null_cache.ex +++ b/test/support/null_cache.ex @@ -21,9 +21,11 @@ defmodule Pleroma.NullCache do def get(_, _), do: {:ok, nil} @impl true - def fetch!(_, _, func) do - {_, res} = func.() - res + def fetch!(_, key, func) do + case func.(key) do + {_, res} -> res + res -> res + end end @impl true |