If caching is globally disabled force dogpile to use the null backend
Due to the way caching is disabled the SHOULD_CACHE_FN() is used to determine if new values are stored in the cache backend, and is only called when the regeneration is required. If dogpile is configured to connect to a memcache, redis, etc to store data it is possible with caching disabled to still pull values from the cache (SHOULD_CACHE_FN has no bearing on reads). The issue described only impacts the use of the memoization decorator. This change forces dogpile to use the null backend if caching is globally disabled to ensure no data is read from the external cache. This will not affect subsystem disabling of cache. Even with cache disabled but reads coming from the external cache, there stale data is not a concern as invalidates will still be processed and the data from the backend will eventually timeout in most cases. Change-Id: I845b6cc18faa2be516676eeacc574473ca84c995 Closes-Bug: #1567413
This commit is contained in:
parent
e686318c5e
commit
ea191cacb1
@ -15,6 +15,8 @@
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
_DEFAULT_BACKEND = 'dogpile.cache.null'
|
||||
|
||||
FILE_OPTIONS = {
|
||||
'cache': [
|
||||
cfg.StrOpt('config_prefix', default='cache.oslo',
|
||||
@ -35,7 +37,7 @@ FILE_OPTIONS = {
|
||||
# prevent issues with the memory cache ending up in "production"
|
||||
# unintentionally, we register a no-op as the keystone default caching
|
||||
# backend.
|
||||
cfg.StrOpt('backend', default='dogpile.cache.null',
|
||||
cfg.StrOpt('backend', default=_DEFAULT_BACKEND,
|
||||
help='Dogpile.cache backend module. It is recommended '
|
||||
'that Memcache with pooling '
|
||||
'(oslo_cache.memcache_pool) or Redis '
|
||||
|
@ -114,7 +114,9 @@ def _build_cache_config(conf):
|
||||
"""
|
||||
prefix = conf.cache.config_prefix
|
||||
conf_dict = {}
|
||||
conf_dict['%s.backend' % prefix] = conf.cache.backend
|
||||
conf_dict['%s.backend' % prefix] = _opts._DEFAULT_BACKEND
|
||||
if conf.cache.enabled is True:
|
||||
conf_dict['%s.backend' % prefix] = conf.cache.backend
|
||||
conf_dict['%s.expiration_time' % prefix] = conf.cache.expiration_time
|
||||
for argument in conf.cache.backend_argument:
|
||||
try:
|
||||
|
@ -23,6 +23,7 @@ from oslo_config import cfg
|
||||
from oslo_config import fixture as config_fixture
|
||||
from oslotest import base
|
||||
|
||||
from oslo_cache import _opts
|
||||
from oslo_cache import core as cache
|
||||
from oslo_cache import exception
|
||||
|
||||
@ -266,6 +267,19 @@ class CacheRegionTest(BaseTestCase):
|
||||
config_dict['test_prefix.arguments.arg2'])
|
||||
self.assertNotIn('test_prefix.arguments.arg3', config_dict)
|
||||
|
||||
def test_cache_dictionary_config_builder_global_disabled(self):
|
||||
"""Validate the backend is reset to default if caching is disabled."""
|
||||
self.config_fixture.config(group='cache',
|
||||
enabled=False,
|
||||
config_prefix='test_prefix',
|
||||
backend='some_test_backend')
|
||||
|
||||
self.assertFalse(self.config_fixture.conf.cache.enabled)
|
||||
config_dict = cache._build_cache_config(self.config_fixture.conf)
|
||||
self.assertEqual(
|
||||
_opts._DEFAULT_BACKEND,
|
||||
config_dict['test_prefix.backend'])
|
||||
|
||||
def test_cache_debug_proxy(self):
|
||||
single_value = 'Test Value'
|
||||
single_key = 'testkey'
|
||||
|
Loading…
Reference in New Issue
Block a user