Skip to content

Commit

Permalink
use caching extras so we know about api_version (bug 582103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Balogh committed Aug 13, 2010
1 parent 75b42a4 commit 1d8b98c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/amo/ext.py
Expand Up @@ -10,13 +10,13 @@ class FragmentCacheExtension(caching.ext.FragmentCacheExtension):
def process_cache_arguments(self, args):
args.append(nodes.Getattr(nodes.ContextReference(), 'request', 'load'))

def _cache_support(self, name, obj, timeout, request, caller):
def _cache_support(self, name, obj, timeout, extra, request, caller):
if isinstance(request, jinja2.runtime.Undefined):
key = name
else:
key = '%s:%s' % (name, request.APP.id)
sup = super(FragmentCacheExtension, self)._cache_support
return sup(key, obj, timeout, caller)
return sup(key, obj, timeout, extra, caller)


cache = FragmentCacheExtension
2 changes: 1 addition & 1 deletion apps/api/templates/api/includes/addon.xml
@@ -1,4 +1,4 @@
{% cache addon %}
{% cache addon, extra=[api_version] %}
<addon id="{{ addon.id }}">
<name>{{ addon.name }}</name>
<type id="{{ addon.type }}">{{ amo.ADDON_TYPE[addon.type] }}</type>
Expand Down
10 changes: 10 additions & 0 deletions apps/api/tests.py
Expand Up @@ -92,6 +92,16 @@ class APITest(TestCase):
fixtures = ('base/apps', 'base/addon_3615', 'base/addon_4664_twitterbar',
'base/addon_5299_gcal', )

def test_api_caching(self):
response = self.client.get('/en-US/firefox/api/1.5/addon/3615')
eq_(response.status_code, 200)
self.assertContains(response, '<author id="')

# Make sure we don't cache the 1.5 response for 1.2.
response = self.client.get('/en-US/firefox/api/1.2/addon/3615')
eq_(response.status_code, 200)
self.assertContains(response, '<author>')

def test_redirection(self):
"""
Test that /api/addon is redirected to /api/LATEST_API_VERSION/addon
Expand Down
2 changes: 1 addition & 1 deletion requirements/prod.txt
Expand Up @@ -17,7 +17,7 @@ importlib==1.0.2
django-pylibmc==0.2.1

-e git://github.com/jbalogh/django-multidb-router.git#egg=django-multidb-router
-e git://github.com/jbalogh/django-cache-machine.git@c8af0214#egg=django-cache-machine
-e git://github.com/jbalogh/django-cache-machine.git@89ce18eb8fa#egg=django-cache-machine
-e git://github.com/jbalogh/jingo.git#egg=jingo
-e git://github.com/jsocol/jingo-minify.git#egg=jingo-minify
-e git://github.com/jsocol/bleach.git#egg=bleach
Expand Down

0 comments on commit 1d8b98c

Please sign in to comment.