我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用werkzeug.contrib.cache.MemcachedCache()。
def make_cache(self): return cache.MemcachedCache(key_prefix='werkzeug-test-case:')
def __init__(self, app): cache_type = app.config.get('CACHE_TYPE') if cache_type == 'memcached': host = app.config.get('MEMCACHE_HOST') self._cache = cache.MemcachedCache([host]) elif cache_type == 'appengine': self._cache = cache.MemcachedCache() elif cache_type == 'local': self._cache = cache.SimpleCache() else: self._cache = cache.NullCache()
def __init__(self): self.cache = MemcachedCache(['127.0.0.1:11211'])
def test_memcached(self): """ Test the memcached """ # Write config self.write_config([ "from edmunds.cache.drivers.memcached import Memcached \n", "APP = { \n", " 'cache': { \n", " 'enabled': True, \n", " 'instances': [ \n", " { \n", " 'name': 'memcached',\n", " 'driver': Memcached,\n", " 'servers': ['127.0.0.1:11211'], \n", " 'default_timeout': 300, \n", " 'key_prefix': None, \n", " }, \n", " ], \n", " }, \n", "} \n", ]) # Create app app = self.create_application() driver = app.cache() self.assert_is_instance(driver, Memcached) self.assert_is_instance(driver, MemcachedCache)
def test_memcached_in_gae(self): """ Test the memcached in Google App Engine """ # Write config self.write_config([ "from edmunds.cache.drivers.memcached import Memcached \n", "APP = { \n", " 'cache': { \n", " 'enabled': True, \n", " 'instances': [ \n", " { \n", " 'name': 'memcached',\n", " 'driver': Memcached,\n", " }, \n", " ], \n", " }, \n", "} \n", ]) # Create app app = self.create_application() driver = app.cache() self.assert_is_instance(driver, Memcached) self.assert_is_instance(driver, MemcachedCache) self.assert_is_instance(driver._client, memcache.Client)
def __init__(self): if webapp.config['APP_ENV'] == 'dev': from werkzeug.contrib.cache import SimpleCache self.cache = SimpleCache() else: from werkzeug.contrib.cache import MemcachedCache self.cache = MemcachedCache(['127.0.0.1:11211'])