本文整理汇总了Python中beaker.cache.CacheManager.get_cache方法的典型用法代码示例。如果您正苦于以下问题:Python CacheManager.get_cache方法的具体用法?Python CacheManager.get_cache怎么用?Python CacheManager.get_cache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beaker.cache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.get_cache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_client_behaviors
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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
示例2: test_client_behaviors
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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
示例3: init_cache
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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)
示例4: setup_caching
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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
示例5: __init__
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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')
示例6: SessionManager
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
class SessionManager(object):
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)
def get_session(self, event):
ns = '.'.join([event['recipient']['id'],event['sender']['id']])
cache = self.cachemgr.get_cache(ns)
return Session(cache)
示例7: __init__
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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"))
示例8: test_cache
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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)
示例9: __init__
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
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]
示例10: make_app
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
def make_app(global_conf,
pub_key,
key_type='RSA',
cookie_name=None,
hdr_prefix=None,
log_name=None,
**app_conf):
"""Paste application factory"""
pub_key = RSA.load_pub_key(pub_key) if key_type == 'RSA' else DSA.load_pub_key(pub_key)
params = {}
if cookie_name is not None:
params['cookie_name'] = cookie_name
if hdr_prefix is not None:
params['hdr_prefix'] = hdr_prefix
if log_name is not None:
params['log_name'] = log_name
cache_opts = parse_cache_config_options(app_conf)
if cache_opts.get('enabled') == True:
cache_mgr = CacheManager(**cache_opts)
cache = cache_mgr.get_cache('tickets_cache')
params['cache'] = cache
return AuthRequestApp(pub_key, **params)
示例11: createCacheFile
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
def createCacheFile():
cache = CacheManager(**parse_cache_config_options(cache_opts))
tmpl_cache = cache.get_cache('mytemplate', type='file', expire=5)
示例12: __init__
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
class Source:
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')
def url_cache_get_or_abort(self, url, code):
try:
val = self.url_cache._get_value(url)
if val.has_value():
ret = val._get_value()
if ret:
return ret
raise SourceError(code)
except Exception:
raise SourceError(code)
def url_cache_get_or_raise(self, url, error):
val = self.url_cache._get_value(url)
if val.has_value():
val.namespace.acquire_read_lock()
try:
_stored, _expired, ret = val._get_value()
if ret:
return ret
except Exception:
raise error
finally:
val.namespace.release_read_lock()
raise error
def cache(self, *args, **kwargs):
return self.cache_manager.cache(*args, **kwargs)
def cache_with_id(self, key):
def decorate(fn):
def wrapper(*args, **kwargs):
def create_id_cache_value():
return fn(*args, **kwargs)
return self.id_cache.get(key=key, createfunc=create_id_cache_value)
def source(self, url):
def decorate(fn):
def wrapper(*args, **kwargs):
def create_url_cache_value():
headers = {}
stored_etag = self.etag_cache.get(key=url, createfunc=lambda:None)
if stored_etag:
headers = {'If-None-Match': stored_etag}
request = urllib2.Request(url, headers=headers)
error = None
error_code = None
try:
response = urllib2.urlopen(request)
except urllib2.HTTPError, e:
error_code = e.code
error = e
except urllib2.URLError, e:
error = e
if error_code == 304:
return self.url_cache_get_or_raise(url, error)
if error_code in (404, 410, 451):
return flask.abort(e.code)
if error:
return self.url_cache_get_or_raise(url, error)
etag = response.info().getheader('ETag', None)
if etag:
self.etag_cache.put(key=url, value=etag)
return response.read()
def create_fn_cache_value():
if url:
val = self.url_cache.get(key=url, createfunc=create_url_cache_value)
return fn(val, *args, **kwargs)
else:
return fn(*args, **kwargs)
try:
return self.fn_cache.get(key=fn.__name__+url, createfunc=create_fn_cache_value)
except SourceError, e:
return flask.abort(e.code)
示例13: CacheManager
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
import uuid
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
from decimal import Decimal#depois apagar isto quando tirar daqui o to_decimal
import traceback
import ujson
cache_opts = {
'cache.type': 'memory',
'cache.data_dir': '/tmp/cache/data',
'cache.lock_dir': '/tmp/cache/lock'
}
cache = CacheManager(**parse_cache_config_options(cache_opts))
erp_cache = cache.get_cache('erp_cache', type='memory', expire=10)
short_cache = cache.get_cache('short_cache', type='memory', expire=10)
def get_context(window_id):
#print('Im on get_context', window_id)
with open('../tmp/{window_id}ctx.json'.format(window_id=window_id), mode='r' , encoding='utf-8') as json_file:
json_string = json_file.read()
#print (json_string)
ctx_dict = ujson.loads(json_string)
return ctx_dict
def set_context(window_id, ctx_dict):
#print('Im on set_context', window_id)
#print (ctx_dict)
示例14: CacheManager
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
f.close()
redirect_uri = dns + '/redirect'
client_id = '569529233074-a9eq4l7argkbjfv1opcp2kdbf2b2hc2b.apps.googleusercontent.com'
client_secret = 'ugqrZlVwM814f9Rmc5_3UGPZ'
#cache
cache_opts = {
'cache.type': 'file',
'cache.data_dir': '/tmp/cache/data',
'cache.lock_dir': '/tmp/cache/lock'
}
cache = CacheManager(**parse_cache_config_options(cache_opts))
tmpl_cache = cache.get_cache(redirect_uri, type='dbm', expire = 3600)
tmpl_cache.clear()
#configure middleware
session_opts = {
'session.type': 'file',
'session.cookie_expires': 300,
'session.data_dir': './data',
'session.auto': True
}
wsgi_app = SessionMiddleware(bottle.app(), session_opts)
@route('/')
def home():
示例15: CacheManager
# 需要导入模块: from beaker.cache import CacheManager [as 别名]
# 或者: from beaker.cache.CacheManager import get_cache [as 别名]
pool = gevent.pool.Pool(40)
import soundcloud
from time import time, strptime, mktime,clock
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
cache_opts = {
'cache.type': 'file',
'cache.data_dir': 'cache/data',
'cache.lock_dir': 'cache/lock'
}
#Cache stores search results for 24 hours
cm = CacheManager(**parse_cache_config_options(cache_opts))
cache = cm.get_cache('trackcache', type='dbm', expire=3600*24)
client = soundcloud.Client(client_id='af912f440f0d027065e7351089b08a52')
def getPlaysPer(track):
created_time = strptime(track.created_at[:-6],"%Y/%m/%d %H:%M:%S")
plays_per = track.playback_count / ((time() - mktime(created_time)) / (3600*24))
return plays_per
def getHype(track):
if(track.playback_count > 500):
hyperatio = float(track.favoritings_count) / float(track.playback_count)
playsper = getPlaysPer(track)
hype = (track.playback_count*playsper)**(hyperatio)
return hype