mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
Adds the ability to replace/extend caching backend (#7856)
* Add ability to override cache backend with custom module * Tests for setup_cache * Add custom CACHE_CONFIG documentation * Fix linter errors and documentation link * Fix black formatting errors
This commit is contained in:
committed by
Maxime Beauchemin
parent
7946165e6e
commit
df051813d5
@@ -20,6 +20,8 @@ import unittest
|
||||
from unittest.mock import patch
|
||||
import uuid
|
||||
|
||||
from flask import Flask
|
||||
from flask_caching import Cache
|
||||
import numpy
|
||||
|
||||
from superset import app
|
||||
@@ -39,6 +41,7 @@ from superset.utils.core import (
|
||||
parse_human_timedelta,
|
||||
parse_js_uri_path_item,
|
||||
parse_past_timedelta,
|
||||
setup_cache,
|
||||
validate_json,
|
||||
zlib_compress,
|
||||
zlib_decompress_to_string,
|
||||
@@ -766,6 +769,35 @@ class UtilsTestCase(unittest.TestCase):
|
||||
self.assertIsNone(parse_js_uri_path_item(None))
|
||||
self.assertIsNotNone(parse_js_uri_path_item("item"))
|
||||
|
||||
def test_setup_cache_no_config(self):
|
||||
app = Flask(__name__)
|
||||
cache_config = None
|
||||
self.assertIsNone(setup_cache(app, cache_config))
|
||||
|
||||
def test_setup_cache_null_config(self):
|
||||
app = Flask(__name__)
|
||||
cache_config = {"CACHE_TYPE": "null"}
|
||||
self.assertIsNone(setup_cache(app, cache_config))
|
||||
|
||||
def test_setup_cache_standard_config(self):
|
||||
app = Flask(__name__)
|
||||
cache_config = {
|
||||
"CACHE_TYPE": "redis",
|
||||
"CACHE_DEFAULT_TIMEOUT": 60,
|
||||
"CACHE_KEY_PREFIX": "superset_results",
|
||||
"CACHE_REDIS_URL": "redis://localhost:6379/0",
|
||||
}
|
||||
assert isinstance(setup_cache(app, cache_config), Cache) is True
|
||||
|
||||
def test_setup_cache_custom_function(self):
|
||||
app = Flask(__name__)
|
||||
CustomCache = type("CustomCache", (object,), {"__init__": lambda *args: None})
|
||||
|
||||
def init_cache(app):
|
||||
return CustomCache(app, {})
|
||||
|
||||
assert isinstance(setup_cache(app, init_cache), CustomCache) is True
|
||||
|
||||
def test_get_stacktrace(self):
|
||||
with app.app_context():
|
||||
app.config["SHOW_STACKTRACE"] = True
|
||||
|
||||
Reference in New Issue
Block a user