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


Python cache.get_cache方法代码示例

本文整理汇总了Python中django.core.cache.get_cache方法的典型用法代码示例。如果您正苦于以下问题:Python cache.get_cache方法的具体用法?Python cache.get_cache怎么用?Python cache.get_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.cache的用法示例。


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

示例1: get_cache_key

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def get_cache_key(request, key_prefix=None, method='GET', cache=None):
    """
    Returns a cache key based on the request path and query. It can be used
    in the request phase because it pulls the list of headers to take into
    account from the global path registry and uses those to build a cache key
    to check against.

    If there is no headerlist stored, the page needs to be rebuilt, so this
    function returns None.
    """
    if key_prefix is None:
        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    cache_key = _generate_cache_header_key(key_prefix, request)
    if cache is None:
        cache = get_cache(settings.CACHE_MIDDLEWARE_ALIAS)
    headerlist = cache.get(cache_key, None)
    if headerlist is not None:
        return _generate_cache_key(request, method, headerlist, key_prefix)
    else:
        return None 
开发者ID:blackye,项目名称:luscan-devel,代码行数:22,代码来源:cache.py

示例2: __init__

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def __init__(self):
        self.cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
        self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
        self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
        self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
        self.cache = get_cache(self.cache_alias) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:8,代码来源:cache.py

示例3: learn_cache_key

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None):
    """
    Learns what headers to take into account for some request path from the
    response object. It stores those headers in a global path registry so that
    later access to that path will know what headers to take into account
    without building the response object itself. The headers are named in the
    Vary header of the response, but we want to prevent response generation.

    The list of headers to use for cache key generation is stored in the same
    cache as the pages themselves. If the cache ages some data out of the
    cache, this just means that we have to build the response once to get at
    the Vary header and so at the list of headers to use for the cache key.
    """
    if key_prefix is None:
        key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
    if cache_timeout is None:
        cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
    cache_key = _generate_cache_header_key(key_prefix, request)
    if cache is None:
        cache = get_cache(settings.CACHE_MIDDLEWARE_ALIAS)
    if response.has_header('Vary'):
        headerlist = ['HTTP_'+header.upper().replace('-', '_')
                      for header in cc_delim_re.split(response['Vary'])]
        cache.set(cache_key, headerlist, cache_timeout)
        return _generate_cache_key(request, request.method, headerlist, key_prefix)
    else:
        # if there is no Vary header, we still need a cache key
        # for the request.get_full_path()
        cache.set(cache_key, [], cache_timeout)
        return _generate_cache_key(request, request.method, [], key_prefix) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:32,代码来源:cache.py

示例4: set_cached_choices

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def set_cached_choices(self,choices):
        if not self.cache_config['enabled']:
            return
        c = get_cache(self.cache_config['cache'])
        return c.set(self.cache_config['key']%self.field_path,choices) 
开发者ID:madre,项目名称:devops,代码行数:7,代码来源:filters.py

示例5: increment_counter

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def increment_counter(self):
        cache = get_cache('default')
        try:
            cache.incr(self.COUNTER_CACHE_KEY)
        except ValueError:
            cache.set(self.COUNTER_CACHE_KEY, 1, self.PERIOD_LENGTH_IN_SECONDS)
        return cache.get(self.COUNTER_CACHE_KEY) 
开发者ID:ResEnv,项目名称:chain-api,代码行数:9,代码来源:logging.py

示例6: cache

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def cache(self):
        """Memoize access to the cache backend."""
        if self._cache is None:
            self._cache = django_cache.get_cache(self.cache_name)
        return self._cache 
开发者ID:rbarrois,项目名称:throttle,代码行数:7,代码来源:django.py

示例7: _incr_cache

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def _incr_cache(self):
        if not self.cache_keys:
            return {}

        cache = get_cache(settings.ST_RATELIMIT_CACHE)
        cache_values = cache.get_many(self.cache_keys)

        for key in self.cache_keys:
            if key in cache_values:
                cache_values[key] += 1
            else:
                cache_values[key] = 1

        cache.set_many(cache_values, timeout=self.time)
        return cache_values 
开发者ID:SPARLab,项目名称:BikeMaps,代码行数:17,代码来源:ratelimit.py

示例8: index_context

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def index_context():
    if settings.ENABLE_CACHING:
        context = get_cache('persistent').get('home.index_context')
    else:
        context = {}
    if not context:
        context = update_index_context_task()
    return context 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:10,代码来源:views.py

示例9: _get_locale_list

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def _get_locale_list():
    """Return a list of locales only for those having 2-letter codes
    """
    local_cache = cache.get_cache('default')
    locale_list_in_cache = local_cache.get('locale')

    if locale_list_in_cache:
        return locale_list_in_cache

    response = api.get('orgs', 'OCL', 'sources', 'Locales', 'concepts', params={'limit': 0})

    if response.status_code == 404:
        locale_list = [{'code': 'en', 'name': 'en - English'}]
        return locale_list

    locale_list = [
        {
            'code': locale['locale'],
            'name': locale['display_name'] + ' [' + locale['locale'] + ']'
        }
        for locale in response.json() if locale['locale']
        ]
    locale_list.sort()

    day_time_as_minutes = 24 * 60 * 60

    local_cache.set('locale', locale_list, day_time_as_minutes)
    return locale_list 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:30,代码来源:views.py

示例10: get_cached_choices

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def get_cached_choices(self):
        if not self.cache_config['enabled']:
            return None
        c = get_cache(self.cache_config['cache'])
        return c.get(self.cache_config['key']%self.field_path) 
开发者ID:madre,项目名称:devops,代码行数:7,代码来源:filters.py

示例11: get_cache

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def get_cache(cache_name):
    if hasattr(caches, '__call__'):
        return caches(cache_name)
    return caches[cache_name] 
开发者ID:pbs,项目名称:django-heartbeat,代码行数:6,代码来源:memcached_status.py

示例12: _get_cache_by_alias

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def _get_cache_by_alias(alias):
        if alias == DEFAULT_CACHE_ALIAS:
            from django.core.cache import cache
        else:
            try:
                from django.core.cache import caches
                cache = caches[alias]
            except ImportError:
                from django.core.cache import get_cache
                cache = get_cache(alias)
        return cache 
开发者ID:Bahus,项目名称:easy_cache,代码行数:13,代码来源:core.py

示例13: __init__

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import get_cache [as 别名]
def __init__(self, cache_timeout=None, cache_anonymous_only=None, **kwargs):
        # We need to differentiate between "provided, but using default value",
        # and "not provided". If the value is provided using a default, then
        # we fall back to system defaults. If it is not provided at all,
        # we need to use middleware defaults.

        cache_kwargs = {}

        try:
            self.key_prefix = kwargs['key_prefix']
            if self.key_prefix is not None:
                cache_kwargs['KEY_PREFIX'] = self.key_prefix
            else:
                self.key_prefix = ''
        except KeyError:
            self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
            cache_kwargs['KEY_PREFIX'] = self.key_prefix

        try:
            self.cache_alias = kwargs['cache_alias']
            if self.cache_alias is None:
                self.cache_alias = DEFAULT_CACHE_ALIAS
            if cache_timeout is not None:
                cache_kwargs['TIMEOUT'] = cache_timeout
        except KeyError:
            self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
            if cache_timeout is None:
                cache_kwargs['TIMEOUT'] = settings.CACHE_MIDDLEWARE_SECONDS
            else:
                cache_kwargs['TIMEOUT'] = cache_timeout

        if cache_anonymous_only is None:
            self.cache_anonymous_only = getattr(settings, 'CACHE_MIDDLEWARE_ANONYMOUS_ONLY', False)
        else:
            self.cache_anonymous_only = cache_anonymous_only

        if self.cache_anonymous_only:
            msg = "CACHE_MIDDLEWARE_ANONYMOUS_ONLY has been deprecated and will be removed in Django 1.8."
            warnings.warn(msg, PendingDeprecationWarning, stacklevel=1)

        self.cache = get_cache(self.cache_alias, **cache_kwargs)
        self.cache_timeout = self.cache.default_timeout 
开发者ID:mediafactory,项目名称:yats,代码行数:44,代码来源:cache.py


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