Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Don't use the deprecated enable-query-caching value (#69256)

Nathan Voxlandf3e1558740c3
diff --git a/src/metabase/cache/core.clj b/src/metabase/cache/core.clj
index b92e6b32862..e44dce512ae 100644
--- a/src/metabase/cache/core.clj
+++ b/src/metabase/cache/core.clj
@@ -16,6 +16,5 @@
root-strategy]
[metabase.cache.settings
enable-query-caching
- enable-query-caching!
query-caching-max-kb
query-caching-max-ttl])
diff --git a/src/metabase/cache/settings.clj b/src/metabase/cache/settings.clj
index 0a09840cba7..8cbb8692391 100644
--- a/src/metabase/cache/settings.clj
+++ b/src/metabase/cache/settings.clj
@@ -2,14 +2,17 @@
(:require
[metabase.settings.core :as setting :refer [defsetting]]
[metabase.util :as u]
- [metabase.util.i18n :refer [deferred-tru tru]]))
+ [metabase.util.i18n :refer [deferred-tru tru]]
+ [toucan2.core :as t2]))
(defsetting enable-query-caching
(deferred-tru "Allow caching results of queries that take a long time to run.")
:type :boolean
:default true
:visibility :authenticated
- :audit :getter)
+ :audit :getter
+ :getter #(t2/exists? :model/CacheConfig)
+ :setter :none)
(def ^:private ^:const global-max-caching-kb
"Although depending on the database, we can support much larger cached values (1GB for PG, 2GB for H2 and 4GB for
diff --git a/src/metabase/query_processor/middleware/cache.clj b/src/metabase/query_processor/middleware/cache.clj
index 1d922ab6dd5..aed4d9c95be 100644
--- a/src/metabase/query_processor/middleware/cache.clj
+++ b/src/metabase/query_processor/middleware/cache.clj
@@ -223,9 +223,6 @@
(fn [metadata]
(save-results-xform start-time-ns metadata query-hash cache-strategy (rff metadata)))))))))
-(defn- caching-enabled? []
- (cache/enable-query-caching))
-
(defn- has-cache-strategy? [cache-strategy]
(some? cache-strategy))
@@ -233,26 +230,22 @@
(not= (:type cache-strategy) :nocache))
(defn- is-cacheable?
- "Returns true if query caching is enabled and the query has a valid cache strategy."
+ "Returns true if the query has a valid cache strategy."
[{:keys [cache-strategy], :as _query}]
- (let [enabled? (caching-enabled?)
- has-strat? (has-cache-strategy? cache-strategy)
+ (let [has-strat? (has-cache-strategy? cache-strategy)
not-nocache? (strategy-not-nocache? cache-strategy)]
- (and enabled? has-strat? not-nocache?)))
+ (and has-strat? not-nocache?)))
(defn- get-cache-eligibility-description
"Returns a descriptive string explaining why a query is or isn't cacheable."
[{:keys [cache-strategy], :as _query}]
- (let [enabled? (caching-enabled?)
- has-strat? (has-cache-strategy? cache-strategy)
+ (let [has-strat? (has-cache-strategy? cache-strategy)
not-nocache? (strategy-not-nocache? cache-strategy)]
- (if (and enabled? has-strat? not-nocache?)
- (str "query caching is enabled; "
- "cache strategy provided: " (pr-str cache-strategy) "; "
+ (if (and has-strat? not-nocache?)
+ (str "cache strategy provided: " (pr-str cache-strategy) "; "
"cache strategy type is not :nocache")
(str/join ", "
(cond-> []
- (not enabled?) (conj "query caching is disabled")
(not has-strat?) (conj "no cache strategy provided")
(not not-nocache?) (conj "cache strategy is :nocache"))))))
diff --git a/test/metabase/cache/settings_test.clj b/test/metabase/cache/settings_test.clj
index 7ea7aa4e1bb..925439cd3fc 100644
--- a/test/metabase/cache/settings_test.clj
+++ b/test/metabase/cache/settings_test.clj
@@ -2,7 +2,21 @@
(:require
[clojure.test :refer :all]
[metabase.cache.settings :as cache.settings]
- [metabase.test :as mt]))
+ [metabase.test :as mt]
+ [toucan2.core :as t2]))
+
+(deftest enable-query-caching-test
+ (t2/with-transaction [_conn nil {:rollback-only true}]
+ (testing "returns false when no CacheConfig rows exist"
+ (t2/delete! :model/CacheConfig)
+ (is (false? (cache.settings/enable-query-caching))))
+ (testing "returns true when CacheConfig rows exist"
+ (t2/insert! :model/CacheConfig {:model "root"
+ :model_id 0
+ :strategy :ttl
+ :config {:multiplier 1
+ :min_duration_ms 1}})
+ (is (true? (cache.settings/enable-query-caching))))))
(deftest query-caching-max-kb-test
(testing (str "Make sure Max Cache Entry Size can be set via with a string value, which is what comes back from the "
diff --git a/test/metabase/query_processor/middleware/cache_test.clj b/test/metabase/query_processor/middleware/cache_test.clj
index f4b565b40ca..977744a2602 100644
--- a/test/metabase/query_processor/middleware/cache_test.clj
+++ b/test/metabase/query_processor/middleware/cache_test.clj
@@ -44,7 +44,6 @@
#_{:clj-kondo/ignore [:metabase/validate-deftest]}
(use-fixtures :once (fn [thunk]
(initialize/initialize-if-needed! :db)
- (metabase.cache.core/enable-query-caching! true)
(thunk)))
(def ^:private ^:dynamic *save-chan*
@@ -184,11 +183,7 @@
nil false}]
(testing (format "cache strategy = %s" (pr-str cache-strategy))
(is (= expected
- (boolean (#'cache/is-cacheable? {:cache-strategy cache-strategy}))))))
- (testing "but enable-query-caching setting is still respected"
- (mt/with-temporary-setting-values [enable-query-caching false]
- (is (= false
- (boolean (#'cache/is-cacheable? {:cache-strategy (ttl-strategy)})))))))))
+ (boolean (#'cache/is-cacheable? {:cache-strategy cache-strategy})))))))))
(deftest empty-cache-test
(testing "if there's nothing in the cache, cached results should *not* be returned"