aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/plugs/cache.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-09-12 21:37:36 +0300
committerrinpatch <rinpatch@sdf.org>2019-09-12 21:37:36 +0300
commit769fb778d41df77c2514b5e3c663f3f624c0a266 (patch)
treea81a7d986ed2330c30ba1ec44aafda12e592c1dc /lib/pleroma/plugs/cache.ex
parent50269e9cacdbb7834c31fc7ad9872b68977e9f10 (diff)
downloadpleroma-769fb778d41df77c2514b5e3c663f3f624c0a266.tar.gz
Track object/create activity fetches
Diffstat (limited to 'lib/pleroma/plugs/cache.ex')
-rw-r--r--lib/pleroma/plugs/cache.ex16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/pleroma/plugs/cache.ex b/lib/pleroma/plugs/cache.ex
index a81a861d0..42d77fc1f 100644
--- a/lib/pleroma/plugs/cache.ex
+++ b/lib/pleroma/plugs/cache.ex
@@ -20,6 +20,7 @@ defmodule Pleroma.Plugs.Cache do
- `ttl`: An expiration time (time-to-live). This value should be in milliseconds or `nil` to disable expiration. Defaults to `nil`.
- `query_params`: Take URL query string into account (`true`), ignore it (`false`) or limit to specific params only (list). Defaults to `true`.
+ - `tracking_fun`: A function that is called on successfull responses, no matter if the request is cached or not. It should accept a conn as the first argument and the value assigned to `tracking_fun_data` as the second.
Additionally, you can overwrite the TTL inside a controller action by assigning `cache_ttl` to the connection struct:
@@ -56,6 +57,10 @@ defmodule Pleroma.Plugs.Cache do
{:ok, nil} ->
cache_resp(conn, opts)
+ {:ok, {content_type, body, tracking_fun_data}} ->
+ conn = opts.tracking_fun(conn, tracking_fun_data)
+ send_cached(conn, {content_type, body})
+
{:ok, record} ->
send_cached(conn, record)
@@ -90,7 +95,16 @@ defmodule Pleroma.Plugs.Cache do
content_type = content_type(conn)
record = {content_type, body}
- Cachex.put(:web_resp_cache, key, record, ttl: ttl)
+ conn =
+ unless opts[:tracking_fun] do
+ Cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl)
+ conn
+ else
+ tracking_fun_data = Map.get(conn.assigns, :tracking_fun_data, nil)
+ Cachex.put(:web_resp_cache, {content_type, body, tracking_fun_data}, record, ttl: ttl)
+
+ opts.tracking_fun.(conn, tracking_fun_data)
+ end
put_resp_header(conn, "x-cache", "MISS from Pleroma")