Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Fix bug 1104124 - Use memcache for kumascript response caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
jezdez committed Feb 11, 2015
1 parent 88fb220 commit 90ff296
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions kuma/wiki/kumascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import requests

from django.conf import settings
from django.core.cache import cache
from django.contrib.sites.models import Site

import constance.config

from kuma.core.cache import memcache

from .constants import KUMASCRIPT_TIMEOUT_ERROR, TEMPLATE_TITLE_PREFIX


Expand Down Expand Up @@ -162,7 +163,7 @@ def get(document, cache_control, base_url, timeout=None):
add_env_headers(headers, env_vars)

# Set up for conditional GET, if we have the details cached.
c_meta = cache.get_many([ck_etag, ck_modified])
c_meta = memcache.get_many([ck_etag, ck_modified])
if ck_etag in c_meta:
headers['If-None-Match'] = c_meta[ck_etag]
if ck_modified in c_meta:
Expand All @@ -173,7 +174,7 @@ def get(document, cache_control, base_url, timeout=None):

if resp.status_code == 304:
# Conditional GET was a pass, so use the cached content.
c_result = cache.get_many([ck_body, ck_errors])
c_result = memcache.get_many([ck_body, ck_errors])
resp_body = c_result.get(ck_body, '').decode('utf-8')
resp_errors = c_result.get(ck_errors, None)

Expand All @@ -183,14 +184,14 @@ def get(document, cache_control, base_url, timeout=None):

# Cache the request for conditional GET, but use the max_age for
# the cache timeout here too.
cache.set(ck_etag, resp.headers.get('etag'),
timeout=max_age)
cache.set(ck_modified, resp.headers.get('last-modified'),
timeout=max_age)
cache.set(ck_body, resp_body.encode('utf-8'),
timeout=max_age)
memcache.set(ck_etag, resp.headers.get('etag'),
timeout=max_age)
memcache.set(ck_modified, resp.headers.get('last-modified'),
timeout=max_age)
memcache.set(ck_body, resp_body.encode('utf-8'),
timeout=max_age)
if resp_errors:
cache.set(ck_errors, resp_errors, timeout=max_age)
memcache.set(ck_errors, resp_errors, timeout=max_age)

elif resp.status_code is None:
resp_errors = KUMASCRIPT_TIMEOUT_ERROR
Expand Down

0 comments on commit 90ff296

Please sign in to comment.