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


Python cache.caches方法代码示例

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


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

示例1: get_remote_symptom_codes

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def get_remote_symptom_codes(group):
    """
    Remote lookup for symptom codes
    """
    symptoms = {}
    cache = caches['comptia']
    # First, try to load from global cache (updated every 24h)
    data = cache.get('codes') or {}

    if not data:
        # ... then try to fetch from GSX
        GsxAccount.fallback()
        data = gsxws.comptia.fetch()
        cache.set('codes', data)

    for k, v in data.get(group):
        symptoms[k] = v

    return symptoms 
开发者ID:fpsw,项目名称:Servo,代码行数:21,代码来源:parts.py

示例2: get_cache_key

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def get_cache_key(request, key_prefix=None, method='GET', cache=None):
    """
    Returns a cache key based on the request URL and query. It can be used
    in the request phase because it pulls the list of headers to take into
    account from the global URL 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 = caches[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:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:cache.py

示例3: benchmark

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def benchmark(self, query_str, to_list=True, num_queries=1):
        # Clears the cache before a single benchmark to ensure the same
        # conditions across single benchmarks.
        caches[settings.CACHALOT_CACHE].clear()

        self.query_name = query_str
        query_str = 'Test.objects.using(using)' + query_str
        if to_list:
            query_str = 'list(%s)' % query_str
        self.query_function = eval('lambda using: ' + query_str)

        with override_settings(CACHALOT_ENABLED=False):
            self.bench_once(CONTEXTS[0], num_queries)

        self.bench_once(CONTEXTS[1], num_queries, invalidate_before=True)

        self.bench_once(CONTEXTS[2], 0) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:19,代码来源:benchmark.py

示例4: run

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def run(self):
        for db_alias in settings.DATABASES:
            self.db_alias = db_alias
            self.db_vendor = connections[self.db_alias].vendor
            print('Benchmarking %s…' % self.db_vendor)
            for cache_alias in settings.CACHES:
                cache = caches[cache_alias]
                self.cache_name = cache.__class__.__name__[:-5].lower()
                with override_settings(CACHALOT_CACHE=cache_alias):
                    self.execute_benchmark()

        self.df = pd.DataFrame.from_records(self.data)
        if not os.path.exists(RESULTS_PATH):
            os.mkdir(RESULTS_PATH)
        self.df.to_csv(os.path.join(RESULTS_PATH, 'data.csv'))

        self.xlim = (0, self.df['time'].max() * 1.01)
        self.output('db')
        self.output('cache') 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:21,代码来源:benchmark.py

示例5: get_cache_key

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

    If there isn't a headerlist stored, return None, indicating that the page
    needs to be rebuilt.
    """
    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 = caches[settings.CACHE_MIDDLEWARE_ALIAS]
    headerlist = cache.get(cache_key)
    if headerlist is not None:
        return _generate_cache_key(request, method, headerlist, key_prefix)
    else:
        return None 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:22,代码来源:cache.py

示例6: get_cached_user

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def get_cached_user(request):
    if not hasattr(request, '_cached_user'):
        try:
            key = CACHE_KEY.format(request.session[SESSION_KEY])
            cache = caches['default']
            user = cache.get(key)
        except KeyError:
            user = AnonymousUser()
        if user is None:
            user = get_user(request)
            cache = caches['default']
            # 8 hours
            cache.set(key, user, 28800)
            logger.debug('No User Cache. Setting now: {0}, {1}'.format(key, user.username))
        request._cached_user = user
    return request._cached_user 
开发者ID:dkarchmer,项目名称:django-aws-template,代码行数:18,代码来源:middleware.py

示例7: get_redis_client

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def get_redis_client():
    global _client

    if _client is not None:
        return _client

    try:
        cache = caches['userlog']
    except KeyError:
        raise ImproperlyConfigured("No 'userlog' cache found in CACHES.")

    try:
        try:
            _client = cache.client                  # django-redis
        except AttributeError:
            _client = cache.get_master_client()     # django-redis-cache
        assert isinstance(_client, redis.StrictRedis)
    except (AssertionError, AttributeError):
        raise ImproperlyConfigured("'userlog' cache doesn't use Redis.")

    return _client 
开发者ID:aaugustin,项目名称:django-userlog,代码行数:23,代码来源:util.py

示例8: dispatch

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def dispatch(self, request, *args, **kwargs):
        """ Fetches queried data from graphql and returns cached & hashed key. """
        if not graphql_api_settings.CACHE_ACTIVE:
            return self.super_call(request, *args, **kwargs)

        cache = caches["default"]
        operation_ast = self.get_operation_ast(request)
        if operation_ast and operation_ast.operation == "mutation":
            cache.clear()
            return self.super_call(request, *args, **kwargs)

        cache_key = "_graplql_{}".format(self.fetch_cache_key(request))
        response = cache.get(cache_key)

        if not response:
            response = self.super_call(request, *args, **kwargs)

            # cache key and value
            cache.set(cache_key, response, timeout=graphql_api_settings.CACHE_TIMEOUT)

        return response 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:23,代码来源:views.py

示例9: get

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def get(self, request, pk):
        # 获取文章详情
        obj = self.get_obj(pk)
        if not obj:
            raise Http404()

        ctx = {
            'art': obj,
            'tags': ContextUtil.random_tags(),
            'cnxh': self.get_cnxh(obj),
            'others': self.get_others(obj),
            'next': self.get_next(obj),
            'prev': self.get_prev(obj),
            'liked': self.get_art_like_status(pk),
        }
        # 更新阅读次数
        obj.read += 1
        obj.save(update_fields=('read',))
        obj.like += caches['four'].get('like_{}'.format(pk), 0)
        return render(request, 'db/detail.html', ctx) 
开发者ID:jeeyshe,项目名称:ishare,代码行数:22,代码来源:views.py

示例10: test_check_cache_default

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def test_check_cache_default():
    cache.caches = cache.CacheHandler()
    assert contrib.check_cache_default() 
开发者ID:mvantellingen,项目名称:django-healthchecks,代码行数:5,代码来源:test_contrib.py

示例11: test_check_cache_default_down

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def test_check_cache_default_down(settings):
    """Check if the application can connect to the default cached and
    read/write some dummy data.

    """
    cache.caches = cache.CacheHandler()
    settings.CACHES={
        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        }
    }
    assert not contrib.check_cache_default() 
开发者ID:mvantellingen,项目名称:django-healthchecks,代码行数:14,代码来源:test_contrib.py

示例12: __init__

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def __init__(self, *args, **kwargs):
        super(CacheMixin, self).__init__(*args, **kwargs)

        # borrowed from FetchFromCacheMiddleware
        self.key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
        self.cache_alias = settings.CACHE_MIDDLEWARE_ALIAS
        self.cache = caches[self.cache_alias] 
开发者ID:sfu-fas,项目名称:coursys,代码行数:9,代码来源:rest.py

示例13: default_response_headers

# 需要导入模块: from django.core import cache [as 别名]
# 或者: from django.core.cache import caches [as 别名]
def default_response_headers(self):
        # shouldn't be necessary since we're setting "cache-control: private" and delivering by HTTPS, but be sure
        # there's no cross-contamination in caches
        h = super(CacheMixin, self).default_response_headers
        h['Vary'] = 'Accept, Authorization, Cookie'
        return h 
开发者ID:sfu-fas,项目名称:coursys,代码行数:8,代码来源:rest.py

示例14: get_cached_choices

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

示例15: set_cached_choices

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


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