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/object.ex | |
parent | 9a744d49c824e0a7d9963b00893fb2091e3ac4ab (diff) | |
download | pleroma-713612c37725c81b0906b03528c9eaa474816c7d.tar.gz |
Cachex: Make caching provider switchable at runtime.
Defaults to Cachex.
Diffstat (limited to 'lib/pleroma/object.ex')
-rw-r--r-- | lib/pleroma/object.ex | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 052ad413b..b4a994da9 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -23,6 +23,8 @@ defmodule Pleroma.Object do @derive {Jason.Encoder, only: [:data]} + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + schema "objects" do field(:data, :map) @@ -156,9 +158,9 @@ defmodule Pleroma.Object do def get_cached_by_ap_id(ap_id) do key = "object:#{ap_id}" - with {:ok, nil} <- Cachex.get(:object_cache, key), + with {:ok, nil} <- @cachex.get(:object_cache, key), object when not is_nil(object) <- get_by_ap_id(ap_id), - {:ok, true} <- Cachex.put(:object_cache, key, object) do + {:ok, true} <- @cachex.put(:object_cache, key, object) do object else {:ok, object} -> object @@ -216,13 +218,13 @@ defmodule Pleroma.Object do end def invalid_object_cache(%Object{data: %{"id" => id}}) do - with {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do - Cachex.del(:web_resp_cache, URI.parse(id).path) + with {:ok, true} <- @cachex.del(:object_cache, "object:#{id}") do + @cachex.del(:web_resp_cache, URI.parse(id).path) end end def set_cache(%Object{data: %{"id" => ap_id}} = object) do - Cachex.put(:object_cache, "object:#{ap_id}", object) + @cachex.put(:object_cache, "object:#{ap_id}", object) {:ok, object} end |