". Skipping unknown format: %s') LOG.error(msg, argument)
continue
arg_key = '.'.join([prefix, 'arguments', argname])
conf_dict[arg_key] = argvalue
LOG.debug(_('Keystone Cache Config: %s'), conf_dict)
return conf_dict
def configure_cache_region(region):
"""Configure a cache region.
:param region: optional CacheRegion object, if not provided a new region
will be instantiated
:raises: exception.ValidationError
:returns: dogpile.cache.CacheRegion
"""
if not isinstance(region, dogpile.cache.CacheRegion):
raise exception.ValidationError(
_('region not type dogpile.cache.CacheRegion'))
if 'backend' not in region.__dict__:
# NOTE(morganfainberg): this is how you tell if a region is configured.
# There is a request logged with dogpile.cache upstream to make this
# easier / less ugly.
config_dict = build_cache_config()
region.configure_from_config(config_dict,
'%s.' % CONF.cache.config_prefix)
if CONF.cache.debug_cache_backend:
region.wrap(DebugProxy)
# NOTE(morganfainberg): if the backend requests the use of a
# key_mangler, we should respect that key_mangler function. If a
# key_mangler is not defined by the backend, use the sha1_mangle_key
# mangler provided by dogpile.cache. This ensures we always use a fixed
# size cache-key. This is toggle-able for debug purposes; if disabled
# this could cause issues with certain backends (such as memcached) and
# its limited key-size.
if region.key_mangler is None:
if CONF.cache.use_key_mangler:
region.key_mangler = util.sha1_mangle_key
for class_path in CONF.cache.proxies:
# NOTE(morganfainberg): if we have any proxy wrappers, we should
# ensure they are added to the cache region's backend. Since
# configure_from_config doesn't handle the wrap argument, we need
# to manually add the Proxies. For information on how the
# ProxyBackends work, see the dogpile.cache documents on
# "changing-backend-behavior"
cls = importutils.import_class(class_path)
LOG.debug(_("Adding cache-proxy '%s' to backend."), class_path)
region.wrap(cls)
return region
def should_cache_fn(section):
"""Build a function that returns a config section's caching status.
For any given driver in keystone that has caching capabilities, a boolean
config option for that driver's section (e.g. ``token``) should exist and
default to ``True``. This function will use that value to tell the caching
decorator if caching for that driver is enabled. To properly use this
with the decorator, pass this function the configuration section and assign
the result to a variable. Pass the new variable to the caching decorator
as the named argument ``should_cache_fn``. e.g.::
from keystone.common import cache
SHOULD_CACHE = cache.should_cache_fn('token')
@cache.on_arguments(should_cache_fn=SHOULD_CACHE)
def function(arg1, arg2):
...
:param section: name of the configuration section to examine
:type section: string
:returns: function reference
"""
**** CubicPower OpenStack Study ****
def function(arg1, arg2):
...
:param section: name of the configuration section to examine
:type section: string
:returns: function reference
"""
**** CubicPower OpenStack Study ****
def should_cache(value):
if not CONF.cache.enabled:
return False
conf_group = getattr(CONF, section)
return getattr(conf_group, 'caching', True)
return should_cache
def key_generate_to_str(s):
# NOTE(morganfainberg): Since we need to stringify all arguments, attempt
# to stringify and handle the Unicode error explicitly as needed.
try:
return str(s)
except UnicodeEncodeError:
return s.encode('utf-8')
def function_key_generator(namespace, fn, to_str=key_generate_to_str):
# NOTE(morganfainberg): This wraps dogpile.cache's default
# function_key_generator to change the default to_str mechanism.
return util.function_key_generator(namespace, fn, to_str=to_str)
REGION = dogpile.cache.make_region(
function_key_generator=function_key_generator)
on_arguments = REGION.cache_on_arguments
**** CubicPower OpenStack Study ****
def key_generate_to_str(s):
# NOTE(morganfainberg): Since we need to stringify all arguments, attempt
# to stringify and handle the Unicode error explicitly as needed.
try:
return str(s)
except UnicodeEncodeError:
return s.encode('utf-8')
**** CubicPower OpenStack Study ****
def function_key_generator(namespace, fn, to_str=key_generate_to_str):
# NOTE(morganfainberg): This wraps dogpile.cache's default
# function_key_generator to change the default to_str mechanism.
return util.function_key_generator(namespace, fn, to_str=to_str)
REGION = dogpile.cache.make_region(
function_key_generator=function_key_generator)
on_arguments = REGION.cache_on_arguments