当前位置: 首页>>代码示例>>Python>>正文


Python cache.CacheManager类代码示例

本文整理汇总了Python中beaker.cache.CacheManager的典型用法代码示例。如果您正苦于以下问题:Python CacheManager类的具体用法?Python CacheManager怎么用?Python CacheManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CacheManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_client_behaviors

    def test_client_behaviors(self):
        config = {
            "cache.lock_dir": "./lock",
            "cache.data_dir": "./cache",
            "cache.type": "ext:memcached",
            "cache.url": mc_url,
            "cache.memcache_module": "pylibmc",
            "cache.protocol": "binary",
            "cache.behavior.ketama": "True",
            "cache.behavior.cas": False,
            "cache.behavior.receive_timeout": "3600",
            "cache.behavior.send_timeout": 1800,
            "cache.behavior.tcp_nodelay": 1,
            "cache.behavior.auto_eject": "0",
        }
        cache_manager = CacheManager(**parse_cache_config_options(config))
        cache = cache_manager.get_cache("test_behavior", expire=6000)

        with cache.namespace.pool.reserve() as mc:
            assert "ketama" in mc.behaviors
            assert mc.behaviors["ketama"] == 1
            assert "cas" in mc.behaviors
            assert mc.behaviors["cas"] == 0
            assert "receive_timeout" in mc.behaviors
            assert mc.behaviors["receive_timeout"] == 3600
            assert "send_timeout" in mc.behaviors
            assert mc.behaviors["send_timeout"] == 1800
            assert "tcp_nodelay" in mc.behaviors
            assert mc.behaviors["tcp_nodelay"] == 1
            assert "auto_eject" in mc.behaviors
            assert mc.behaviors["auto_eject"] == 0
开发者ID:C-Pro,项目名称:beaker,代码行数:31,代码来源:test_memcached.py

示例2: init_cache

	def init_cache(self):
		cache_opts = {
				'cache.type': 'file',
				'cache.data_dir': '/tmp/cache/data',
				'cache.lock_dir': '/tmp/cache/lock'}
		cm = CacheManager(**parse_cache_config_options(cache_opts))
		return cm.get_cache('schlagzeile', expire=600)
开发者ID:zweifisch,项目名称:schlagzeile,代码行数:7,代码来源:schlagzeile.py

示例3: test_client_behaviors

 def test_client_behaviors(self):
     config = {
         'cache.lock_dir':'./lock', 
         'cache.data_dir':'./cache',  
         'cache.type':'ext:memcached', 
         'cache.url':mc_url,
         'cache.memcache_module':'pylibmc', 
         'cache.protocol':'binary', 
         'cache.behavior.ketama': 'True', 
         'cache.behavior.cas':False, 
         'cache.behavior.receive_timeout':'3600',
         'cache.behavior.send_timeout':1800, 
         'cache.behavior.tcp_nodelay':1,
         'cache.behavior.auto_eject':"0"
     }
     cache_manager = CacheManager(**parse_cache_config_options(config))
     cache = cache_manager.get_cache('test_behavior', expire=6000)
     
     with cache.namespace.pool.reserve() as mc:
         assert "ketama" in mc.behaviors
         assert mc.behaviors["ketama"] == 1
         assert "cas" in mc.behaviors
         assert mc.behaviors["cas"] == 0
         assert "receive_timeout" in mc.behaviors
         assert mc.behaviors["receive_timeout"] == 3600
         assert "send_timeout" in mc.behaviors
         assert mc.behaviors["send_timeout"] == 1800
         assert "tcp_nodelay" in mc.behaviors
         assert mc.behaviors["tcp_nodelay"] == 1
         assert "auto_eject" in mc.behaviors
         assert mc.behaviors["auto_eject"] == 0
开发者ID:01-,项目名称:beaker,代码行数:31,代码来源:test_memcached.py

示例4: __init__

	def __init__(self, namespace, **nsargs):
		super().__init__(namespace, **nsargs)
		cache_opts = {
			'cache.type': 'file',
			'cache.data_dir': 'cache/data',
			'cache.lock_dir': 'cache/lock',
			'cache.short_term.type': 'ext:memcached',
			'cache.short_term.url': '127.0.0.1.11211',
			'cache.short_term.expire': '3600',
			'cache.long_term.type': 'file',
			'cache.long_term.expire': '86400'
		}
		cache_manager = CacheManager(**parse_cache_config_options(cache_opts))
		self.cache = cache_manager.get_cache(namespace, type='dbm')
开发者ID:stretchhog,项目名称:article-recommender,代码行数:14,代码来源:LearningService.py

示例5: test_cache

    def test_cache(self):
        import time
        from beaker.cache import CacheManager
        cm = CacheManager()
        cache = cm.get_cache('auth_pubtkt_middleware', type='memory', expire=3600)
        app = DumbApp()
        app = AuthPubTKTMiddleware(app, rsa_pub, cache=cache)
        env = {}
        env['REMOTE_ADDR'] = '192.168.1.10'
        env['REQUEST_METHOD'] = 'GET'
        env['HTTP_COOKIE'] = 'auth_pubtkt="uid=user1;validuntil=1277190189;cip=192.168.1.10;tokens=editor,moderator;graceperiod=3600;udata=custom data;[email protected];display_name=John;sig=YaMhb5yXkfqOtQ87P5gYeh4kSgQev1c6XjqT0pXT/ojXj/qpswpyqWenNv3y5rcUPT++80zZPBVNFfwPUI5Crps5nHZP55FNPtBE337KYZ6KYoMEVQD6xqnouf5i1Jm5KwB1IfQdr8fvRQs2oqBIMMTkVyfv6yRRNWVPz+7xwxw="'

        
        app(env, dumb_start_response)
        app(env, dumb_start_response)
开发者ID:AndreyPlotnikov,项目名称:auth_pubtkt,代码行数:15,代码来源:tests.py

示例6: __init__

 def __init__(self, config):
     """Creates a cache using the supplied configuration parameters or defaults.
     """
     self.enableCache = (config.get('wmscapabilitycache.enable', 'True').lower() == 'true')
     if self.enableCache:
         cache_opts = {
             'cache.expire': config.get('wmscapabilitycache.expire', None),
             'cache.type': config.get('wmscapabilitycache.type', 'file'),
             'cache.data_dir': config.get('wmscapabilitycache.data_dir', '/tmp/ecomaps/wmscapabilitycache/data'),
             'cache.lock_dir': config.get('wmscapabilitycache.lock_dir', None)
             }
         cacheMgr = CacheManager(**parse_cache_config_options(cache_opts))
 
         self.cache = cacheMgr.get_cache('getWmsCapabilities')
     log.info("WMS capability caching %s" % ("enabled" if self.enableCache else "disabled"))
开发者ID:NERC-CEH,项目名称:jules-jasmin,代码行数:15,代码来源:wms_capability_cache.py

示例7: __init__

 def __init__(self, type='memory', **kwargs):
     opts = kwargs or {
         'data_dir': '/tmp/messengerbot-cache/data',
         'lock_dir': '/tmp/messengerbot-cache/lock'
     }
     opts['type'] = type
     self.cachemgr = CacheManager(**opts)
开发者ID:koslab,项目名称:koslab.messengerbot,代码行数:7,代码来源:session.py

示例8: __init__

 def __init__(self, config):
     cache_opts = {
         'cache.type': getattr(config, 'citation_cache_type', 'file'),
         'cache.data_dir': getattr(config, 'citation_cache_data_dir', None),
         'cache.lock_dir': getattr(config, 'citation_cache_lock_dir', None),
     }
     self._cache = CacheManager(**parse_cache_config_options(cache_opts)).get_cache('doi')
开发者ID:bwlang,项目名称:galaxy,代码行数:7,代码来源:citations.py

示例9: setUp

 def setUp(self):
     reg = {}
     reg['cache.expire'] = 10
     reg['cache.regions'] = 'session'
     reg['cache.type'] = 'memory'
     reg['batch.user.session.timeout'] = 1
     self.cachemgr = CacheManager(**parse_cache_config_options(reg))
     self.backend = BeakerBackend(reg)
开发者ID:SmarterApp,项目名称:RDW_DataWarehouse,代码行数:8,代码来源:test_session_backend.py

示例10: TestBeakerBackend

class TestBeakerBackend(unittest.TestCase):

    def setUp(self):
        reg = {}
        reg['cache.expire'] = 10
        reg['cache.regions'] = 'session'
        reg['cache.type'] = 'memory'
        reg['batch.user.session.timeout'] = 1
        self.cachemgr = CacheManager(**parse_cache_config_options(reg))
        self.backend = BeakerBackend(reg)

    def __get_region(self, key):
        return self.cachemgr.get_cache_region('edware_session_' + key, 'session')

    def test_create_new_session(self):
        session = Session()
        session.set_session_id('123')
        self.backend.create_new_session(session)
        self.assertIsNotNone(self.__get_region('123').get('123'))

    def test_get_session_from_persistence_with_existing_session(self):
        session = Session()
        session.set_session_id('456')
        session.set_uid('abc')
        self.backend.create_new_session(session)
        lookup = self.backend.get_session('456')
        self.assertEqual(lookup.get_uid(), 'abc')

    def test_get_session_invalid_session(self):
        lookup = self.backend.get_session('idontexist')
        self.assertIsNone(lookup)

    def test_delete_session(self):
        session = Session()
        session.set_session_id('456')
        session.set_uid('abc')
        self.backend.create_new_session(session)
        self.backend.delete_session('456')
        self.assertFalse('456' in self.__get_region('456'))

    def test_update_session(self):
        session = Session()
        session.set_session_id('456')
        session.set_uid('abc')
        self.backend.create_new_session(session)
        session.set_uid('def')
        self.backend.update_session(session)
        lookup = self.__get_region('456').get('456')
        self.assertEquals(lookup.get_uid(), 'def')

    def test_overwrite_timeout(self):
        session = Session()
        session.set_session_id('1456')
        session.set_uid('abc')
        self.backend.create_new_session(session, overwrite_timeout=True)
        time.sleep(1)
        self.assertIsNone(self.backend.get_session('1456'))
开发者ID:SmarterApp,项目名称:RDW_DataWarehouse,代码行数:57,代码来源:test_session_backend.py

示例11: __init__

    def __init__(self, app,
                 cookie_cache=True,
                 cache_opts=None,
                 debug=False,
                 cookie_max_age=0,
                 classifiers=[]):
        self.debug = debug
        self.cookie_cache = cookie_cache
        cache_manager = CacheManager(
            **parse_cache_config_options(cache_opts or
                                         self.DEFAULT_CACHE_OPTIONS))
        self.cache = cache_manager.get_cache('mobi.devices')

        if self.debug:
            logger.info('MobiDeviceMiddleware start in debug mode.')
        self.app = app
        self.set_cookie_max_age(int(cookie_max_age))
        self.classifiers = classifiers if isinstance(classifiers, list) \
                else [classifiers]
开发者ID:bbinet,项目名称:mobi.devices,代码行数:19,代码来源:devicedetection.py

示例12: __init__

 def __init__(self, path, expire):
   cache_opts = {
       'cache.type': 'dbm',
       'cache.data_dir': path,
       'cache.expire': expire
       }
   self.cache_manager = CacheManager(**parse_cache_config_options(cache_opts))
   self.etag_cache = self.cache_manager.get_cache('etags', expire=365*24*60*60)
   self.fn_cache = self.cache_manager.get_cache('processed')
   self.url_cache = self.cache_manager.get_cache('urls')
   self.id_cache = self.cache_manager.get_cache('id')
开发者ID:jedahu,项目名称:flog,代码行数:11,代码来源:source.py

示例13: __init__

 def __init__(self):
     self.logger = logging.getLogger('radiovisserver.radiodns')
     self.cache = CacheManager(**parse_cache_config_options(config.CACHE_OPTS)).get_cache('radiodns', expire=60)
     self.durablecache = pylibmc.Client(
         [config.MEMCACHED_HOST],
         binary=True,
         behaviors={
             "tcp_nodelay": True,
             "ketama": True,
         }
     )  # CacheManager(**parse_cache_config_options(config.CACHE_OPTS)).get_cache('radiodnsdurable')
开发者ID:ebu,项目名称:radiodns-plugit,代码行数:11,代码来源:radiodns.py

示例14: BeakerBackend

class BeakerBackend(Backend):
    '''
    Manipulates session that resides in persistent storage (memory, memcached)
    '''
    def __init__(self, settings):
        self.cache_mgr = CacheManager(**parse_cache_config_options(settings))
        self.batch_timeout = int(settings.get('batch.user.session.timeout'))

    def create_new_session(self, session, overwrite_timeout=False):
        '''
        Creates a new session
        '''
        self.update_session(session, overwrite_timeout=overwrite_timeout)

    def update_session(self, session, overwrite_timeout=False):
        '''
        Given a session, persist it
        '''
        _id = session.get_session_id()
        region = self.__get_cache_region(_id)
        # Overwrite the timeout for batch user sessions
        if overwrite_timeout:
            region.expiretime = self.batch_timeout
        region.put(_id, session)

    def get_session(self, session_id):
        '''
        Return session from persistent storage
        '''
        region = self.__get_cache_region(session_id)
        if session_id not in region:
            logger.info('Session is not found in cache. It may have expired or connection to memcached is down')
            return None
        return region.get(session_id)

    def delete_session(self, session_id):
        '''
        Delete session from persistent storage
        '''
        # delete from db doesn't work
        region = self.__get_cache_region(session_id)
        if session_id in region:
            # works for memcached
            region.remove_value(session_id)

    def __get_cache_region(self, key):
        return self.cache_mgr.get_cache_region('edware_session_' + key, 'session')

    def clear(self):
        '''
        clear cache
        '''
        self.cache_region.clear()
开发者ID:SmarterApp,项目名称:RDW_DataWarehouse,代码行数:53,代码来源:session_backend.py

示例15: setup_caching

def setup_caching(config):
    cache_type = config.get('caching', 'type')
    data_dir = config.get('caching', 'data_dir')
    short_expire = config.get('caching', 'short_expire')
    long_expire = config.get('caching', 'long_expire')

    cache_opts = {
        'cache.type': cache_type,
        'cache.data_dir': data_dir,
        'cache.lock_dir': data_dir,
        'cache.regions': 'short_term, long_term',
        'cache.short_term.type': cache_type,
        'cache.short_term.expire': short_expire,
        'cache.long_term.type': cache_type,
        'cache.long_term.expire': long_expire,
    }

    cache_manager = CacheManager(**parse_cache_config_options(cache_opts))
    short_term_cache = cache_manager.get_cache('short_term', expire=short_expire)
    long_term_cache = cache_manager.get_cache('long_term', expire=long_expire)
    return short_term_cache, long_term_cache
开发者ID:lbryio,项目名称:lbryum-server,代码行数:21,代码来源:blockchain_processor.py


注:本文中的beaker.cache.CacheManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。