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


Python cache.cache_control方法代码示例

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


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

示例1: lightbox_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def lightbox_view(request, spatial_context=''):
    """ redirects requests from the legacy site 'lightbox'
        to the media-search view

        We can add URL parameter mappings to this later
        so that old url parameters can be mapped to the
        current parameters
    """
    request = RequestNegotiation().anonymize_request(request)
    url = request.get_full_path()
    new_url = url.replace('/lightbox/', '/media-search/')
    param_suffix = ''
    if '?' in url:
        url_ex = url.split('?')
        param_suffix = '?' + url_ex[1]
    return redirect(new_url, permanent=True)

# @cache_control(no_cache=True)
# @never_cache
# @vary_on_headers('Accept', 'accept', 'content-type') 
开发者ID:ekansa,项目名称:open-context-py,代码行数:22,代码来源:views.py

示例2: index_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def index_view(request):
    """ Get the search context JSON-LD """
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    if 'HTTP_ACCEPT' in request.META:
        req_neg.check_request_support(request.META['HTTP_ACCEPT'])
    if req_neg.supported:
        # requester wanted a mimetype we DO support
        template = loader.get_template('vocabularies/index.html')
        context =  {
            'base_url': base_url,
            'page_title': 'Open Context: Vocabularies + Ontologies',
            'act_nav': 'vocabularies',
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context, request))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)


# @cache_control(no_cache=True)
# @never_cache 
开发者ID:ekansa,项目名称:open-context-py,代码行数:27,代码来源:views.py

示例3: as_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def as_view(cls, **kwargs):
        view = super(NoCacheMixin, cls).as_view(**kwargs)
        return cache_control(
            private=True, no_cache=True, no_store=True, max_age=0)(view) 
开发者ID:mvantellingen,项目名称:django-healthchecks,代码行数:6,代码来源:views.py

示例4: api_cache_control

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def api_cache_control(**kwargs):
    """
    Adds cache headers to a view using our API cache header defaults.
    """
    if settings.API_CACHE_ENABLED:
        directives = {"public": True, "max_age": settings.API_CACHE_TIME}
    else:
        directives = {"no_cache": True, "no_store": True, "must_revalidate": True}

    directives.update(kwargs)
    return cache_control(**directives) 
开发者ID:mozilla,项目名称:normandy,代码行数:13,代码来源:decorators.py

示例5: pub_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def pub_view(request):
    """ Get publishing overview page """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    if 'HTTP_ACCEPT' in request.META:
        req_neg.check_request_support(request.META['HTTP_ACCEPT'])
    if req_neg.supported:
        # requester wanted a mimetype we DO support
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/publishing',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'How to publish archaeological research data '\
                           'with Open Context',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/publishing.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Publishing',
            'act_nav': 'about',
            'og': open_graph,
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context, request))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)


# @cache_control(no_cache=True)
# @never_cache 
开发者ID:ekansa,项目名称:open-context-py,代码行数:39,代码来源:views.py

示例6: sponsors_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def sponsors_view(request):
    """ Get the page about sponsors """
    request = RequestNegotiation().anonymize_request(request)
    rp = RootPath()
    base_url = rp.get_baseurl()
    req_neg = RequestNegotiation('text/html')
    if 'HTTP_ACCEPT' in request.META:
        req_neg.check_request_support(request.META['HTTP_ACCEPT'])
    if req_neg.supported:
        # requester wanted a mimetype we DO support
        open_graph = {
            'twitter_site': settings.TWITTER_SITE,
            'type': 'website',
            'url': base_url + '/about/sponsors',
            'site_name': settings.CANONICAL_SITENAME,
            'description': 'Sources of financial support for '\
                           'Open Context and collaborative institutions providing '\
                           'complementary services',
            'image': base_url + '/static/oc/images/index/oc-blue-square-logo.png',
            'video': False
        }
        template = loader.get_template('about/sponsors.html')
        context = {
            'base_url': base_url,
            'page_title': 'Open Context: About - Intellectual Property',
            'og': open_graph,
            'act_nav': 'about',
            'nav_items': settings.NAV_ITEMS
        }
        return HttpResponse(template.render(context, request))
    else:
        # client wanted a mimetype we don't support
        return HttpResponse(req_neg.error_message,
                            status=415)


# @cache_control(no_cache=True)
# @never_cache 
开发者ID:ekansa,项目名称:open-context-py,代码行数:40,代码来源:views.py

示例7: get_default_cache_control_decorator

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def get_default_cache_control_decorator():
    cache_control_kwargs = get_default_cache_control_kwargs()
    return cache_control(**cache_control_kwargs) 
开发者ID:torchbox,项目名称:wagtail-torchbox,代码行数:5,代码来源:cache.py

示例8: test_cached_control_private_not_cached

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [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

示例9: html_view

# 需要导入模块: from django.views.decorators import cache [as 别名]
# 或者: from django.views.decorators.cache import cache_control [as 别名]
def html_view(request, identifier):
    rp = RootPath()
    base_url = rp.get_baseurl()
    uri = 'http://opencontext.org/vocabularies/' + str(identifier)
    lequiv = LinkEquivalence()
    id_list = lequiv.get_identifier_list_variants(uri)
    lequiv = LinkEquivalence()
    id_s_list = lequiv.get_identifier_list_variants(uri + '/')
    for id_s in id_s_list:
        if id_s not in id_list:
            # add the slashed version to the list
            id_list.append(id_s)
    entity = False
    for test_id in id_list:
        ent = Entity()
        found = ent.dereference(test_id)
        if found is False:
            found = ent.dereference(test_id, test_id)
        if found:
            entity = ent
            break
    if entity is not False:
        t_vocab = TemplateVocab()
        t_vocab.create_template_for_entity(entity)
        t_vocab.make_json_for_html()
        req_neg = RequestNegotiation('text/html')
        req_neg.supported_types = ['application/ld+json',
                                   'application/json']
        if 'HTTP_ACCEPT' in request.META:
            req_neg.check_request_support(request.META['HTTP_ACCEPT'])
        if req_neg.supported:
            if 'json' in req_neg.use_response_type:
                # content negotiation requested JSON or JSON-LD
                json_obj = t_vocab.make_json_obj()
                return HttpResponse(json.dumps(json_obj,
                                    ensure_ascii=False, indent=4),
                                    content_type=req_neg.use_response_type + "; charset=utf8")
            else:
                template = loader.get_template('vocabularies/view.html')
                context = {
                    'item': t_vocab,
                    'base_url': base_url,
                    'page_title': 'Open Context: Vocabularies + Ontologies',
                    'act_nav': 'vocabularies',
                    'nav_items': settings.NAV_ITEMS
                }
                return HttpResponse(template.render(context, request))
        else:
             # client wanted a mimetype we don't support
            return HttpResponse(req_neg.error_message,
                                content_type="text/plain; charset=utf8",
                                status=415)
    else:
        raise Http404


# @cache_control(no_cache=True)
# @never_cache 
开发者ID:ekansa,项目名称:open-context-py,代码行数:60,代码来源:views.py


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