diff options
author | lain <lain@soykaf.club> | 2020-12-18 17:44:46 +0100 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-12-18 17:44:46 +0100 |
commit | 713612c37725c81b0906b03528c9eaa474816c7d (patch) | |
tree | 553b3f7c24875b7ed0fbb58375dcd6904206f47e /lib/pleroma/web/media_proxy.ex | |
parent | 9a744d49c824e0a7d9963b00893fb2091e3ac4ab (diff) | |
download | pleroma-713612c37725c81b0906b03528c9eaa474816c7d.tar.gz |
Cachex: Make caching provider switchable at runtime.
Defaults to Cachex.
Diffstat (limited to 'lib/pleroma/web/media_proxy.ex')
-rw-r--r-- | lib/pleroma/web/media_proxy.ex | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/pleroma/web/media_proxy.ex b/lib/pleroma/web/media_proxy.ex index 8656b8cad..2793cabc1 100644 --- a/lib/pleroma/web/media_proxy.ex +++ b/lib/pleroma/web/media_proxy.ex @@ -12,29 +12,31 @@ defmodule Pleroma.Web.MediaProxy do @base64_opts [padding: false] @cache_table :banned_urls_cache + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + def cache_table, do: @cache_table @spec in_banned_urls(String.t()) :: boolean() - def in_banned_urls(url), do: elem(Cachex.exists?(@cache_table, url(url)), 1) + def in_banned_urls(url), do: elem(@cachex.exists?(@cache_table, url(url)), 1) def remove_from_banned_urls(urls) when is_list(urls) do - Cachex.execute!(@cache_table, fn cache -> - Enum.each(Invalidation.prepare_urls(urls), &Cachex.del(cache, &1)) + @cachex.execute!(@cache_table, fn cache -> + Enum.each(Invalidation.prepare_urls(urls), &@cachex.del(cache, &1)) end) end def remove_from_banned_urls(url) when is_binary(url) do - Cachex.del(@cache_table, url(url)) + @cachex.del(@cache_table, url(url)) end def put_in_banned_urls(urls) when is_list(urls) do - Cachex.execute!(@cache_table, fn cache -> - Enum.each(Invalidation.prepare_urls(urls), &Cachex.put(cache, &1, true)) + @cachex.execute!(@cache_table, fn cache -> + Enum.each(Invalidation.prepare_urls(urls), &@cachex.put(cache, &1, true)) end) end def put_in_banned_urls(url) when is_binary(url) do - Cachex.put(@cache_table, url(url), true) + @cachex.put(@cache_table, url(url), true) end def url(url) when is_nil(url) or url == "", do: nil |