def _doc_page_cache_view(request, document_slug, *args, **kwargs): # We skip caching for authed users or if redirect=no # is in the query string. if (request.user.is_authenticated() or request.GET.get('redirect') == 'no'): statsd.incr('wiki.document_view.cache.skip') return view(request, document_slug, *args, **kwargs) cache_key = doc_html_cache_key( mobile=request.MOBILE, locale=request.LANGUAGE_CODE, slug=document_slug) html = cache.get(cache_key) if html is not None: statsd.incr('wiki.document_view.cache.hit') return HttpResponse(html) statsd.incr('wiki.document_view.cache.miss') response = view(request, document_slug, *args, **kwargs) # We only cache if the response returns HTTP 200. if response.status_code == 200: cache.set(cache_key, response.content) return response
def _doc_page_cache_view(request, document_slug, *args, **kwargs): # We skip caching for authed users or if redirect=no # is in the query string. if request.user.is_authenticated() or request.GET.get("redirect") == "no": statsd.incr("wiki.document_view.cache.skip") return view(request, document_slug, *args, **kwargs) cache_key = doc_html_cache_key( mobile=request.MOBILE, locale=request.LANGUAGE_CODE, slug=document_slug, minimal=request.GET.get("minimal", "0"), ) html, headers = cache.get(cache_key, (None, None)) if html is not None: statsd.incr("wiki.document_view.cache.hit") res = HttpResponse(html) for key, val in headers.items(): res[key] = val return res statsd.incr("wiki.document_view.cache.miss") response = view(request, document_slug, *args, **kwargs) # We only cache if the response returns HTTP 200. if response.status_code == 200: cache.set(cache_key, (response.content, dict(response._headers.values()))) return response