本文整理汇总了Python中pylons.cache.get_cache函数的典型用法代码示例。如果您正苦于以下问题:Python get_cache函数的具体用法?Python get_cache怎么用?Python get_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_cache函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:JustinTulloss,项目名称:harmonize.fm,代码行数:7,代码来源:user.py
示例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)
开发者ID:ahmadiga,项目名称:fookebox,代码行数:30,代码来源:albumart.py
示例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
开发者ID:MrPetru,项目名称:spam,代码行数:35,代码来源:helpers.py
示例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 []
开发者ID:encukou,项目名称:spline,代码行数:7,代码来源:sources.py
示例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)
开发者ID:asuffield,项目名称:openspending,代码行数:7,代码来源:cache.py
示例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
开发者ID:thakadu,项目名称:Abraxas,代码行数:35,代码来源:base.py
示例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)
开发者ID:RandyMoore,项目名称:openspending,代码行数:7,代码来源:cache.py
示例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)
开发者ID:UfSoft,项目名称:python-perl,代码行数:33,代码来源:base.py
示例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
开发者ID:cccarey,项目名称:demisauce,代码行数:7,代码来源:cache.py
示例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
开发者ID:chiehwen,项目名称:tg2,代码行数:7,代码来源:test_caching.py
示例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)
开发者ID:veekun,项目名称:spline,代码行数:59,代码来源:base.py
示例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'))
开发者ID:leondomingo,项目名称:Sapns,代码行数:17,代码来源:shortcuts.py
示例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)
开发者ID:ralphbean,项目名称:mdemos.feeds,代码行数:8,代码来源:root.py
示例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)
开发者ID:AAEMCJALBERT,项目名称:ckan,代码行数:8,代码来源:home.py
示例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
开发者ID:chiehwen,项目名称:tg2,代码行数:8,代码来源:test_caching.py
示例16: do_cron
def do_cron(self, tic, *args, **kwargs):
if tic % self.poll_frequency != 0:
# Too early!
return
updates = self._poll(self.limit, self.max_age)
if updates is not None:
cache.get_cache('spline-frontpage')[self.cache_key()] = updates
return
开发者ID:encukou,项目名称:spline,代码行数:10,代码来源:sources.py
示例17: save
def save(self, page):
namespace, key = create_cache_key(self.show, {'page':page,})
cache.get_cache(namespace).remove(key)
np = self._splitName(page)
newPage = self._fetchPageRaw(page)
if newPage == None:
name = np[1]
if len(name) == 0:
name = '::'
newPage = Page(name)
newPage.namespace = Namespace(np[0])
Session.add(newPage)
newPage.text = request.POST['text']
tags = list()
for i in request.POST['tags'].split(','):
if len(i) > 0:
tags.append(Tag(i))
Session.commit()
redirect('/%s' % page)
开发者ID:seken,项目名称:wikpy,代码行数:19,代码来源:page.py
示例18: delete
def delete(self, id_shortcut, **params):
logger = logging.getLogger(__name__ + '/delete')
try:
logger.info('Deleting shortcut [%s]' % id_shortcut)
# the shortcut to be deleted
sc = dbs.query(SapnsShortcut).get(id_shortcut)
dbs.query(SapnsShortcut).\
filter(SapnsShortcut.shortcut_id == id_shortcut).\
delete()
dbs.flush()
_key = '%d_%d' % (sc.user_id, sc.parent_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)
开发者ID:leondomingo,项目名称:Sapns,代码行数:23,代码来源:shortcuts.py
示例19: _render_from_cache
def _render_from_cache(action, self, *args, **kwargs):
context = dict(
tmpl_context = self._py_object.tmpl_context,
app_globals = self._py_object.config['pylons.app_globals'],
config = self._py_object.config,
request = self._py_object.request,
response = self._py_object.response,
translator = pylons.translator._current_obj(),
session = pylons.session._current_obj(),
)
url = self._py_object.request.url
def createfunc():
context['url'] = routes.util.URLGenerator(context['config']['routes.map'],
context['request'].environ)
headers_copy = {}
for header, value in context['response'].headers.iteritems():
headers_copy[header] = value
for key, value in context.iteritems():
getattr(pylons, key)._push_object(value)
content = action(self, *args, **kwargs)
cached_headers = {}
for header, value in context['response'].headers.iteritems():
if header not in headers_copy or headers_copy[header] != value:
cached_headers[header] = value
log.debug('Headers Copy: %s', headers_copy)
log.debug('Headers: %s', context['response'].headers)
log.debug('Cached Headers: %s', cached_headers)
for key, value in context.iteritems():
getattr(pylons, key)._pop_object(value)
return (cached_headers, content)
if context['app_globals'].cache_enabled:
my_cache = cache.get_cache(
context['config']['templates.namespace'],
type=context['config'].get('beaker.cache.type', 'memory'),
out_of_band=True)
try:
headers, content = my_cache.get_value(
key=url, createfunc=createfunc, expiretime=60)
for header, value in headers.iteritems():
context['response'].headers[header] = value
return content
except NewValueInProgressException:
context['response'].status = 503
return rendering_action(*args, **kwargs)
else:
return action(self, *args, **kwargs)
开发者ID:npilon,项目名称:out_of_band_cache,代码行数:50,代码来源:decorator.py
示例20: all_
def all_(self):
#logger = logging.getLogger('Users.all')
def _all():
#logger.info('Getting all users...')
users = []
for user in dbs.query(SapnsUser).order_by(SapnsUser.user_id):
users.append(dict(id=user.user_id, display_name=user.display_name,
user_name=user.user_name))
return users
_cache = cache.get_cache('users_all')
return dict(users=_cache.get_value(key='all', createfunc=_all, expiretime=0))
开发者ID:leondomingo,项目名称:Sapns,代码行数:14,代码来源:users.py
注:本文中的pylons.cache.get_cache函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论