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


Python cache.cache_page方法代码示例

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


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

示例1: index

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def index(request):
    """
    /stats/
    """
    data = prep_view(request)
    form = TechieStatsForm(initial=data['initial'])

    if request.method == 'POST':
        form = TechieStatsForm(request.POST, initial=data['initial'])
        if form.is_valid():
            request.session['stats_filter'] = form.serialize()

    data['form'] = form
    return render(request, "stats/index.html", data)


#@cache_page(15*60) 
开发者ID:fpsw,项目名称:Servo,代码行数:19,代码来源:stats.py

示例2: cache_qr_code

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def cache_qr_code():
    """
    Decorator that caches the requested page if a settings named 'QR_CODE_CACHE_ALIAS' exists and is not empty or None.
    """
    def decorator(view_func):
        @functools.wraps(view_func)
        def _wrapped_view(request, *view_args, **view_kwargs):
            cache_enabled = request.GET.get('cache_enabled', True)
            if cache_enabled and hasattr(settings, 'QR_CODE_CACHE_ALIAS') and settings.QR_CODE_CACHE_ALIAS:
                # We found a cache alias for storing the generate qr code and cache is enabled, use it to cache the
                # page.
                timeout = settings.CACHES[settings.QR_CODE_CACHE_ALIAS]['TIMEOUT']
                key_prefix = 'token=%s.user_pk=%s' % (request.GET.get('url_signature_enabled') or constants.DEFAULT_URL_SIGNATURE_ENABLED, request.user.pk)
                response = cache_page(timeout, cache=settings.QR_CODE_CACHE_ALIAS, key_prefix=key_prefix)(view_func)(request, *view_args, **view_kwargs)
            else:
                # No cache alias for storing the generated qr code, call the view as is.
                response = (view_func)(request, *view_args, **view_kwargs)
            return response
        return _wrapped_view
    return decorator 
开发者ID:dprog-philippe-docourt,项目名称:django-qr-code,代码行数:22,代码来源:views.py

示例3: test_get_cache_key

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def test_get_cache_key(self):
        request = self.factory.get(self.path)
        response = HttpResponse()
        # Expect None if no headers have been set yet.
        self.assertIsNone(get_cache_key(request))
        # Set headers to an empty list.
        learn_cache_key(request, response)

        self.assertEqual(
            get_cache_key(request),
            'views.decorators.cache.cache_page.settingsprefix.GET.'
            '18a03f9c9649f7d684af5db3524f5c99.d41d8cd98f00b204e9800998ecf8427e'
        )
        # A specified key_prefix is taken into account.
        key_prefix = 'localprefix'
        learn_cache_key(request, response, key_prefix=key_prefix)
        self.assertEqual(
            get_cache_key(request, key_prefix=key_prefix),
            'views.decorators.cache.cache_page.localprefix.GET.'
            '18a03f9c9649f7d684af5db3524f5c99.d41d8cd98f00b204e9800998ecf8427e'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:23,代码来源:tests.py

示例4: find

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def find(request):
    """
    Searching for device from devices/find
    """
    title = _("Device search")
    form = DeviceSearchForm()
    results = Device.objects.none()

    if request.method == 'POST':
        form = DeviceSearchForm(request.POST)
        if form.is_valid():
            fdata = form.cleaned_data
            results = Device.objects.all()

            if fdata.get("product_line"):
                results = results.filter(product_line__in=fdata['product_line'])
            if fdata.get("warranty_status"):
                results = results.filter(warranty_status__in=fdata['warranty_status'])
            if fdata.get("description"):
                results = results.filter(description__icontains=fdata['description'])
            if fdata.get("sn"):
                results = results.filter(sn__icontains=fdata['sn'])
            if fdata.get("date_start"):
                results = results.filter(created_at__range=[fdata['date_start'],
                                         fdata['date_end']])

    page = request.GET.get("page")
    devices = paginate(results, page, 100)

    return render(request, "devices/find.html", locals())


#@cache_page(60*5) 
开发者ID:fpsw,项目名称:Servo,代码行数:35,代码来源:device.py

示例5: cache_on_auth

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def cache_on_auth(timeout):
    """Cache the response based on whether or not the user is authenticated.

    Do NOT use on views that include user-specific information, e.g., CSRF tokens.
    """
    # https://stackoverflow.com/questions/11661503/django-caching-for-authenticated-users-only
    def _decorator(view_func):
        @wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            key_prefix = "_auth_%s_" % request.user.is_authenticated
            return cache_page(timeout, key_prefix=key_prefix)(view_func)(request, *args, **kwargs)
        return _wrapped_view
    return _decorator 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:15,代码来源:decorators.py

示例6: cache_if_anon

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def cache_if_anon(timeout):
    """Cache the view if the user is not authenticated and there are no messages to display."""
    # https://stackoverflow.com/questions/11661503/django-caching-for-authenticated-users-only
    def _decorator(view_func):
        @wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            if request.user.is_authenticated or messages.get_messages(request):
                return view_func(request, *args, **kwargs)
            else:
                return cache_page(timeout)(view_func)(request, *args, **kwargs)
        return _wrapped_view
    return _decorator 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:14,代码来源:decorators.py

示例7: cache

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def cache():
    return cache_page(getattr(settings, 'CACHE_TIME', 0)) \
        if getattr(settings, 'ENABLE_CACHE', False) else lambda x: x 
开发者ID:82Flex,项目名称:DCRM,代码行数:5,代码来源:urls.py

示例8: as_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def as_view(cls, *args, **kwargs):
        view = super().as_view(*args, **kwargs)
        return cache_page(6 * 60 * 60)(view) 
开发者ID:chaoss,项目名称:prospector,代码行数:5,代码来源:graphs.py

示例9: StructureInfo

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def StructureInfo(request, pdbname):
    """
    Show structure details
    """
    protein = Protein.objects.get(signprotstructure__PDB_code=pdbname)

    crystal = SignprotStructure.objects.get(PDB_code=pdbname)

    return render(request,'signprot/structure_info.html',{'pdbname': pdbname, 'protein': protein, 'crystal': crystal})

# @cache_page(60*60*24*2) 
开发者ID:protwis,项目名称:protwis,代码行数:13,代码来源:views.py

示例10: hotspotsView

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def hotspotsView(request):
    """
    Show hotspots viewer page
    """
    return render(request, 'hotspots/hotspotsView.html')

# @cache_page(60*60*24*7) 
开发者ID:protwis,项目名称:protwis,代码行数:9,代码来源:views.py

示例11: g_proteins

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def g_proteins(request, **response_kwargs):
    ''' Example of g_proteins '''
    proteins = Protein.objects.filter(source__name='SWISSPROT').prefetch_related('proteingproteinpair_set')
    jsondata = {}
    for p in proteins:
        gps = p.proteingproteinpair_set.all()
        if gps:
            jsondata[str(p)] = []
            for gp in gps:
                jsondata[str(p)].append(str(gp))
    jsondata = json.dumps(jsondata)
    response_kwargs['content_type'] = 'application/json'
    return HttpResponse(jsondata, **response_kwargs)

# @cache_page(60*60*24*7) 
开发者ID:protwis,项目名称:protwis,代码行数:17,代码来源:views.py

示例12: get_urls

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def get_urls(self):
        urlpatterns = super(ShippingApplication, self).get_urls()
        urlpatterns += patterns('',
            url(r'^city-lookup/(?P<slug>[\w-]+)/$', cache_page(60*10)(self.city_lookup_view.as_view()),
                name='city-lookup'),
        )
        urlpatterns += patterns('',
            url(r'^details/(?P<slug>[\w-]+)/$', cache_page(60*10)(self.shipping_details_view.as_view()),
                name='charge-details'),
        )
        return self.post_process_urls(urlpatterns) 
开发者ID:okfish,项目名称:django-oscar-shipping,代码行数:13,代码来源:app.py

示例13: test_get_cache_key_with_query

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def test_get_cache_key_with_query(self):
        request = self.factory.get(self.path, {'test': 1})
        response = HttpResponse()
        # Expect None if no headers have been set yet.
        self.assertIsNone(get_cache_key(request))
        # Set headers to an empty list.
        learn_cache_key(request, response)
        # The querystring is taken into account.
        self.assertEqual(
            get_cache_key(request),
            'views.decorators.cache.cache_page.settingsprefix.GET.'
            'beaf87a9a99ee81c673ea2d67ccbec2a.d41d8cd98f00b204e9800998ecf8427e'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例14: test_learn_cache_key

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def test_learn_cache_key(self):
        request = self.factory.head(self.path)
        response = HttpResponse()
        response['Vary'] = 'Pony'
        # Make sure that the Vary header is added to the key hash
        learn_cache_key(request, response)

        self.assertEqual(
            get_cache_key(request),
            'views.decorators.cache.cache_page.settingsprefix.GET.'
            '18a03f9c9649f7d684af5db3524f5c99.d41d8cd98f00b204e9800998ecf8427e'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py

示例15: test_cached_control_private_not_cached

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_page [as 别名]
def test_cached_control_private_not_cached(self):
        """Responses with 'Cache-Control: private' are not cached."""
        view_with_private_cache = cache_page(3)(cache_control(private=True)(hello_world_view))
        request = self.factory.get('/view/')
        response = view_with_private_cache(request, '1')
        self.assertEqual(response.content, b'Hello World 1')
        response = view_with_private_cache(request, '2')
        self.assertEqual(response.content, b'Hello World 2') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py


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