當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。