def test_get_client(self, mock_cacheregion): self.assertIsNotNone( cache_utils.get_client(expiration_time=60)) self.flags(group='cache', enabled=True) self.assertIsNotNone( cache_utils.get_client(expiration_time=60)) self.flags(group='cache', enabled=False) client = cache_utils.get_client(expiration_time=60) self.assertIsNotNone(client.region) mock_cacheregion.assert_has_calls( [mock.call('oslo_cache.dict', arguments={'expiration_time': 60}, expiration_time=60), mock.call('dogpile.cache.null', _config_argument_dict=mock.ANY, _config_prefix='cache.oslo.arguments.', expiration_time=60, wrap=None), mock.call('oslo_cache.dict', arguments={'expiration_time': 60}, expiration_time=60)], )
def test_get_client(self, mock_cacheregion): self.assertIsNotNone(cache_utils.get_client(expiration_time=60)) self.flags(memcached_servers=['localhost:11211']) self.assertIsNotNone(cache_utils.get_client(expiration_time=60)) self.flags(memcached_servers=None) self.flags(group='cache', enabled=True) self.assertIsNotNone(cache_utils.get_client(expiration_time=60)) self.flags(memcached_servers=None) self.flags(group='cache', enabled=False) client = cache_utils.get_client(expiration_time=60) self.assertIsNotNone(client.region) mock_cacheregion.assert_has_calls([ mock.call('oslo_cache.dict', arguments={'expiration_time': 60}, expiration_time=60), mock.call('dogpile.cache.memcached', arguments={'url': ['localhost:11211']}, expiration_time=60), mock.call('dogpile.cache.null', _config_argument_dict=mock.ANY, _config_prefix='cache.oslo.arguments.', expiration_time=60, wrap=None), mock.call('oslo_cache.dict', arguments={'expiration_time': 60}, expiration_time=60) ], )
def _get_cache(): global MC if MC is None: MC = cache_utils.get_client(expiration_time=AZ_CACHE_SECONDS) return MC
def __init__(self): self._cache = cache_utils.get_client( expiration_time=CONF.api.metadata_cache_expiration) if (CONF.neutron.service_metadata_proxy and not CONF.neutron.metadata_proxy_shared_secret): LOG.warning("metadata_proxy_shared_secret is not configured, " "the metadata information returned by the proxy " "cannot be trusted")
def memoizer(context, reqid): global _CACHE if not _CACHE: _CACHE = cache_utils.get_client(expiration_time=_CACHE_TIME) key = "%s:%s" % (func.__name__, reqid) key = str(key) value = _CACHE.get(key) if value is None: value = func(context, reqid) _CACHE.set(key, value) return value
def memoizer(context, reqid): global _CACHE if not _CACHE: _CACHE = cache_utils.get_client(expiration_time=_CACHE_TIME) key = "{0!s}:{1!s}".format(func.__name__, reqid) key = str(key) value = _CACHE.get(key) if value is None: value = func(context, reqid) _CACHE.set(key, value) return value
def __init__(self): self._cache = cache_utils.get_client( expiration_time=CONF.metadata_cache_expiration)
def mc_instance(self): if self._mc_instance is None: self._mc_instance = cache_utils.get_client() return self._mc_instance
def mc(self): if self._mc is None: self._mc = cache_utils.get_client(CONF.consoleauth.token_ttl) return self._mc
def mc(self): if self._mc is None: self._mc = cache_utils.get_client(CONF.console_token_ttl) return self._mc
from oslo_log import log as logging import nova.conf from nova import config from nova import objects from nova import context import os from nova import cache_utils LOG = logging.getLogger(__name__) CONF = nova.conf.CONF argv = [] default_config_files = ['/etc/nova/nova.conf'] config.parse_args(argv, default_config_files=default_config_files) objects.register_all() context = context.get_admin_context() os.getpid() mc = cache_utils.get_client(CONF.consoleauth.token_ttl) token = '0d745ccf-ee97-4a26-b504-f87a39c3d060' mc.set(token.encode('UTF-8'), 'asd') mc.get(token.encode('UTF-8')) mc.region.backend.__dict__
All Rights reserved 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 expressed or implied. See the License for the specific language governing permissions and limitations under the License. """ from nova import cache_utils _VM_REFS_CACHE = cache_utils.get_client() def vm_ref_cache_delete(id): global _VM_REFS_CACHE _VM_REFS_CACHE.delete(id) def vm_ref_cache_get(id): global _VM_REFS_CACHE return _VM_REFS_CACHE.get(id) def vm_ref_cache_update(id, item): global _VM_REFS_CACHE value = vm_ref_cache_get(id)