Allow to skip cache in Cache plug
authorTusooa Zhu <tusooa@kazv.moe>
Thu, 5 May 2022 22:39:34 +0000 (18:39 -0400)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 29 Jun 2022 19:47:26 +0000 (20:47 +0100)
Ref: fix-local-public

lib/pleroma/web/plugs/cache.ex

index 935b2d83464fb5f2514c92803a81193d1bf66ba8..b0e44db077e022275828132bf85b52a9b9cdc1b0 100644 (file)
@@ -100,20 +100,19 @@ defmodule Pleroma.Web.Plugs.Cache do
         should_cache = not Map.get(conn.assigns, :skip_cache, false)
 
         conn =
-          unless opts[:tracking_fun] do
-            if should_cache do
-              @cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl)
-            end
+          cond do
+            Map.get(conn.assigns, :skip_cache, false) ->
+              conn
 
-            conn
-          else
-            tracking_fun_data = Map.get(conn.assigns, :tracking_fun_data, nil)
+            !opts[:tracking_fun] ->
+              @cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl)
+              conn
 
-            if should_cache do
+            true ->
+              tracking_fun_data = Map.get(conn.assigns, :tracking_fun_data, nil)
               @cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data}, ttl: ttl)
-            end
 
-            opts.tracking_fun.(conn, tracking_fun_data)
+              opts.tracking_fun.(conn, tracking_fun_data)
           end
 
         put_resp_header(conn, "x-cache", "MISS from Pleroma")