def configure(conf): """Configure the library. This must be called before conf(). :param conf: The configuration object. :type conf: oslo_config.cfg.ConfigOpts """ _opts.configure(conf)
def configure(conf): """Configure the library. Register the required oslo.cache config options into an oslo.config CONF object. This must be called before :py:func:`configure_cache_region`. :param conf: The configuration object. :type conf: oslo_config.cfg.ConfigOpts """ _opts.configure(conf)
def configure(conf): """Configure the library. This must be called before conf(). The following backends are registered in :mod:`dogpile.cache`: * ``oslo_cache.mongo`` - :class:`oslo_cache.backends.mongo.MongoCacheBackend` * ``oslo_cache.memcache_pool`` - :class:`oslo_cache.backends.memcache_pool.PooledMemcachedBackend` * ``oslo_cache.dict`` - :class:`oslo_cache.backends.dictionary.DictCacheBackend` :param conf: The configuration object. :type conf: oslo_config.cfg.ConfigOpts """ _opts.configure(conf) for backend in _BACKENDS: dogpile.cache.register_backend(*backend)
from oslo_cache import core as cache from oslo_cache import _opts from oslo_config import cfg CONF = cfg.CONF _opts.configure(CONF) CONF(default_config_files=['app.ini']) print(CONF.cache.backend) print(CONF.cache.config_prefix) cache.configure(CONF) #def key_maker(namespace, fn, **kwargs): # return "zongzw_" + namespace + fn.__name__ + kwargs #region = cache.create_region(function=key_maker) region = cache.create_region() cache.configure_cache_region(CONF, region) mem_decorator = cache.get_memoization_decorator(CONF, region, "cache") @mem_decorator def func(arg1, arg2): return (arg1, arg2) func('1', '2')
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from oslo_cache import _opts from oslo_config import cfg _opts.configure(cfg.CONF)