本文整理汇总了Python中pylons.cache.get_cache函数的典型用法代码示例。如果您正苦于以下问题:Python get_cache函数的具体用法?Python get_cache怎么用?Python get_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_caches
def _get_caches(self):
self.fbcache = cache.get_cache('fbprofile')
self.fbfriendscache = cache.get_cache('fbfriends')
self.fballfriendscache = cache.get_cache('fballfriends')
# Facebook session_key_expires is not set for some reason
#self._fbexpiration = facebook.session_key_expires - time.time()
self._fbexpiration = 24*60*60 #24 hours
示例2: _getInDirCover
def _getInDirCover(self):
path_cache = cache.get_cache('album_path', type='memory')
key = self.album.key()
dirname = path_cache.get_value(key=key,
createfunc=self.album.getPath, expiretime=60)
if dirname == None:
return None
def best_image(x, y):
pattern = '(cover|album|front)'
if re.match(pattern, x, re.I):
return x
else:
return y
if not (fs.exists(dirname) and fs.isdir(dirname)):
return None
dir = fs.listdir(dirname)
dir = filter(lambda x: x.endswith(
('jpg', 'JPG', 'jpeg', 'JPEG')), dir)
if len(dir) < 1:
return None
bestmatch = reduce(best_image, dir)
return os.path.join(dirname, bestmatch)
示例3: project_get_eager
def project_get_eager(proj):
"""Return a project eagerloaded with its scenes and libgroups
``project_get_eager`` keeps a (thread-local) cache of loaded projects,
reloading instances from the db if the "modified" field is newer then the
cache.
"""
session = session_get()
# get a lazyload instance of the project, save the modified time and discard
curproject = project_get(proj)
modified = curproject.modified
session.expunge(curproject)
# get the project from cache
projcache = cache.get_cache('projects')
project, cached = projcache.get_value(key=proj,
createfunc=eagerload_maker(proj),
expiretime=360)
# check if its older then the db
if cached < modified:
# remove the invalidated value from the cache and reload from db
projcache.remove_value(proj)
project, cached = projcache.get_value(key=proj,
createfunc=eagerload_maker(proj),
expiretime=360)
# put project back into the session if necessary
try:
session.add(project)
except InvalidRequestError:
pass
return project
示例4: poll
def poll(self, global_limit, global_max_age):
"""Fetches cached updates."""
try:
return cache.get_cache('spline-frontpage')[self.cache_key()]
except KeyError:
# Haven't cached anything yet, apparently
return []
示例5: __init__
def __init__(self, dataset, type='dbm'):
self.dataset = dataset
opt = config.get('openspending.cache_enabled', 'True')
self.cache_enabled = asbool(opt) and \
not self.dataset.private
self.cache = cache.get_cache('DSCACHE_' + dataset.name,
type=type)
示例6: __before__
def __before__(self, **kwds):
# Load the hot tags from cache
mycache = cache.get_cache('hot_tags')
log.debug('before call to mycache.get_value("tags"))')
c.tags = mycache.get_value(key='tags', createfunc=Tag.popular,
type="memory", expiretime=3600)
log.debug('after call to mycache.get_value("tags"))')
c.sources = mycache.get_value(key='sources', createfunc=Feed.active_feeds,
type='memory', expiretime=3600)
log.debug('after call to mycache.get_value("feeds"))')
# Pass the logo_file name to the template context
c.logo_file = config.get('logo_file', 'logo.png')
# Pass the site sub-title to the template context
c.subtitle = config.get('banner_subtitle', None)
# Set up pagination
if self.__class__.__name__ == 'EntryController':
if not 'view' in kwds:
return
c.pagesize = 25
c.totlinks = 5000 # Probably should look this up from db and cache it...
c.page = kwds.get('page', 0)
try:
c.page_numeric = long(c.page)
except:
abort(404)
if c.page_numeric < 0:
abort(404)
c.slicestart = c.pagesize * c.page_numeric
示例7: __init__
def __init__(self, type='dbm'):
"""
Initialise a dataset index cache
"""
self.cache_enabled = app_globals.cache_enabled
self.cache = cache.get_cache('DATASET_INDEX_CACHE',
type=type)
示例8: __call__
def __call__(self, environ, start_response):
# Insert any code to be run per request here. The Routes match
# is under environ['pylons.routes_dict'] should you want to check
# the action or route vars here
# Grab Domain Info
self.domain = request.environ['REMOTE_USER']
self.dominfo = get_domain_info(self.domain)
# Don't allow Locked Domains to make any changes
if self.dominfo['ispmanDomainLocked'] == 'true' and \
request.path_info != '/locked':
h.redirect_to('/locked')
elif request.path_info == '/':
h.redirect_to('/domain')
ccache = cache.get_cache('navigation')
c.menus = ccache.get_value('i18n_menus',
createfunc=self.__create_i18n_menus,
type='memory', expiretime=3600)
c.controller = request.environ['pylons.routes_dict']['controller']
c.action = request.environ['pylons.routes_dict']['action']
c.imgs_list = self.__images_list()
if 'message' in session and session['message'] != '':
c.message = session['message']
session['message'] = ''
session.save()
return WSGIController.__call__(self, environ, start_response)
示例9: get
def get(self, key, default=None):
mycache = pylonscache.get_cache('demisauce')
try:
myvalue = mycache.get_value(key)
except KeyError:
return default
return myvalue
示例10: simple
def simple(self, a):
c = cache.get_cache("BasicTGController.index")
x = c.get_value(key=a,
createfunc=lambda: "cached %s" % a,
type="memory",
expiretime=3600)
return x
示例11: cache_content
def cache_content(self, key, do_work, template):
"""Argh!
Okay, so. Use this when you want to cache the BODY of a page but not
the CHROME (i.e., wrapper or base or whatever).
``key``
The key that uniquely identifies this particular rendering of this
page content.
``do_work``
Some function that will stuff a bunch of expensive data in c. This
will only be called if the page hasn't yet been cached. It'll be
passed the key.
``template``
Name of the template to use.
Also, DO NOT FORGET TO wrap the cachable part of your template in a
<%lib:cache_content> tag, or nothing will get cached!
If a page body is pulled from cache, c.timer.from_cache will be set to
True. If the page had to be generated, it will be set to False. (If
this function wasn't involved at all, it will be set to None.)
"""
# Content needs to be cached per-language
key = u"{0}/{1}".format(key, c.lang)
# Cache for... ten hours? Sure, whatever
content_cache = cache.get_cache("content_cache:" + template, expiretime=36000)
# XXX This is dumb. Caches don't actually respect the 'enabled'
# setting, so we gotta fake it.
if not content_cache.nsargs.get("enabled", True):
def skip_cache(context, mako_def):
do_work(key)
mako_def.body()
c._cache_me = skip_cache
return render(template)
# These pages can be pretty big. In the case of e.g. memcached, that's
# a lot of RAM spent on giant pages that consist half of whitespace.
# Solution: gzip everything. Use level 1 for speed!
def cache_me(context, mako_def):
c.timer.from_cache = True
def generate_page():
c.timer.from_cache = False
do_work(key)
return zlib.compress(capture(context, mako_def.body).encode("utf8"), 1)
context.write(zlib.decompress(content_cache.get_value(key=key, createfunc=generate_page)).decode("utf8"))
c._cache_me = cache_me
return render(template)
示例12: bookmark
def bookmark(self, id_shortcut, **params):
logger = logging.getLogger(__name__ + '/bookmark')
try:
logger.info('Bookmarking shortcut [%s]' % id_shortcut)
user = dbs.query(SapnsUser).get(request.identity['user'].user_id)
dboard = user.get_dashboard()
dboard.add_child(id_shortcut)
_key = '%d_%d' % (user.user_id, dboard.shortcut_id)
cache.get_cache('user_get_shortcuts').remove_value(key=_key)
return dict(status=True)
except Exception, e:
logger.error(e)
return dict(status=False) #, message=str(e).decode('utf-8'))
示例13: init_tree
def init_tree(self, key, fresh=False, **kw):
c = cache.get_cache('feeds')
if fresh:
return self._get_feed_titles(fresh=fresh)
else:
return c.get_value(key='feed_titles',
createfunc=self._get_feed_titles,
expiretime=3600)
示例14: cache
def cache(self, id):
'''Manual way to clear the caches'''
if id == 'clear':
wui_caches = ['stats']
for cache_name in wui_caches:
cache_ = cache.get_cache(cache_name, type='dbm')
cache_.clear()
return 'Cleared caches: %s' % ', '.join(wui_caches)
示例15: expiry
def expiry(self, a):
mockdb['expiry'] = a # inject a value into the context
c = cache.get_cache("BasicTGController.index")
x = c.get_value(key='test',
createfunc=self.createfunc,
type="memory",
expiretime=100)
return x