mirror of
https://github.com/apache/superset.git
synced 2026-06-07 08:39:25 +00:00
feat: rename TABLE_NAMES_CACHE_CONFIG to DATA_CACHE_CONFIG (#11509)
* feat: rename TABLE_NAMES_CACHE_CONFIG to DATA_CACHE_CONFIG The corresponding cache will now also cache the query results. * Slice use DATA_CACHE_CONFIG CACHE_DEFAULT_TIMEOUT * Add test for default cache timeout * rename FAR_FUTURE to ONE_YEAR_IN_SECS
This commit is contained in:
@@ -17,7 +17,8 @@
|
||||
"""Unit tests for Superset with caching"""
|
||||
import json
|
||||
|
||||
from superset import cache, db
|
||||
from superset import app, db
|
||||
from superset.extensions import cache_manager
|
||||
from superset.utils.core import QueryStatus
|
||||
|
||||
from .base_tests import SupersetTestCase
|
||||
@@ -25,15 +26,42 @@ from .base_tests import SupersetTestCase
|
||||
|
||||
class TestCache(SupersetTestCase):
|
||||
def setUp(self):
|
||||
cache.clear()
|
||||
self.login(username="admin")
|
||||
cache_manager.cache.clear()
|
||||
cache_manager.data_cache.clear()
|
||||
|
||||
def tearDown(self):
|
||||
cache.clear()
|
||||
cache_manager.cache.clear()
|
||||
cache_manager.data_cache.clear()
|
||||
|
||||
def test_no_data_cache(self):
|
||||
app.config["DATA_CACHE_CONFIG"] = {"CACHE_TYPE": "null"}
|
||||
cache_manager.init_app(app)
|
||||
|
||||
def test_cache_value(self):
|
||||
self.login(username="admin")
|
||||
slc = self.get_slice("Girls", db.session)
|
||||
json_endpoint = "/superset/explore_json/{}/{}/".format(
|
||||
slc.datasource_type, slc.datasource_id
|
||||
)
|
||||
resp = self.get_json_resp(
|
||||
json_endpoint, {"form_data": json.dumps(slc.viz.form_data)}
|
||||
)
|
||||
resp_from_cache = self.get_json_resp(
|
||||
json_endpoint, {"form_data": json.dumps(slc.viz.form_data)}
|
||||
)
|
||||
self.assertFalse(resp["is_cached"])
|
||||
self.assertFalse(resp_from_cache["is_cached"])
|
||||
|
||||
def test_slice_data_cache(self):
|
||||
# Override cache config
|
||||
app.config["CACHE_DEFAULT_TIMEOUT"] = 100
|
||||
app.config["DATA_CACHE_CONFIG"] = {
|
||||
"CACHE_TYPE": "simple",
|
||||
"CACHE_DEFAULT_TIMEOUT": 10,
|
||||
"CACHE_KEY_PREFIX": "superset_data_cache",
|
||||
}
|
||||
cache_manager.init_app(app)
|
||||
|
||||
slc = self.get_slice("Boys", db.session)
|
||||
json_endpoint = "/superset/explore_json/{}/{}/".format(
|
||||
slc.datasource_type, slc.datasource_id
|
||||
)
|
||||
@@ -45,6 +73,19 @@ class TestCache(SupersetTestCase):
|
||||
)
|
||||
self.assertFalse(resp["is_cached"])
|
||||
self.assertTrue(resp_from_cache["is_cached"])
|
||||
# should fallback to default cache timeout
|
||||
self.assertEqual(resp_from_cache["cache_timeout"], 10)
|
||||
self.assertEqual(resp_from_cache["status"], QueryStatus.SUCCESS)
|
||||
self.assertEqual(resp["data"], resp_from_cache["data"])
|
||||
self.assertEqual(resp["query"], resp_from_cache["query"])
|
||||
# should exists in `data_cache`
|
||||
self.assertEqual(
|
||||
cache_manager.data_cache.get(resp_from_cache["cache_key"])["query"],
|
||||
resp_from_cache["query"],
|
||||
)
|
||||
# should not exists in `cache`
|
||||
self.assertIsNone(cache_manager.cache.get(resp_from_cache["cache_key"]))
|
||||
|
||||
# reset cache config
|
||||
app.config["DATA_CACHE_CONFIG"] = {"CACHE_TYPE": "null"}
|
||||
cache_manager.init_app(app)
|
||||
|
||||
Reference in New Issue
Block a user