diff --git a/apps/amo/tests/__init__.py b/apps/amo/tests/__init__.py index df03f3a792..18b4b3cfb2 100644 --- a/apps/amo/tests/__init__.py +++ b/apps/amo/tests/__init__.py @@ -18,6 +18,7 @@ from django.http import SimpleCookie from django.test.client import Client from django.utils import translation +import caching import elasticutils.contrib.django as elasticutils import mock import pyelasticsearch.exceptions as pyelasticsearch @@ -275,6 +276,9 @@ class TestCase(MockEsMixin, RedisTest, test_utils.TestCase): def _pre_setup(self): super(TestCase, self)._pre_setup() cache.clear() + # Override django-cache-machine caching.base.TIMEOUT because it's + # computed too early, before settings_test.py is imported. + caching.base.TIMEOUT = settings.CACHE_COUNT_TIMEOUT @contextmanager def activate(self, locale=None, app=None): diff --git a/apps/translations/models.py b/apps/translations/models.py index 92e8c8f6ab..23bf0fe081 100644 --- a/apps/translations/models.py +++ b/apps/translations/models.py @@ -56,13 +56,13 @@ class Translation(amo.models.ModelBase): @property def cache_key(self): - return self._cache_key(self.id) + return self._cache_key(self.id, self._state.db) @classmethod - def _cache_key(cls, pk): + def _cache_key(cls, pk, db): # Hard-coding the class name here so that subclasses don't try to cache # themselves under something like "o:translations.purifiedtranslation". - key_parts = ('o', 'translations.translation', pk) + key_parts = ('o', 'translations.translation', pk, db) return ':'.join(map(encoding.smart_unicode, key_parts)) @classmethod diff --git a/docs/settings/settings_local.prod.py b/docs/settings/settings_local.prod.py index 39c72effea..572b149e8d 100644 --- a/docs/settings/settings_local.prod.py +++ b/docs/settings/settings_local.prod.py @@ -31,7 +31,7 @@ SLAVE_DATABASES = ['slave'] # Use IP:PORT pairs separated by semicolons. CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', 'LOCATION': ['localhost:11211', 'localhost:11212'], 'TIMEOUT': 500, } diff --git a/docs/topics/install-zamboni/advanced-installation.rst b/docs/topics/install-zamboni/advanced-installation.rst index da0f3a3413..2bc900e057 100644 --- a/docs/topics/install-zamboni/advanced-installation.rst +++ b/docs/topics/install-zamboni/advanced-installation.rst @@ -43,7 +43,7 @@ We slipped this in with the basic install. The package was CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', 'LOCATION': ['localhost:11211'], 'TIMEOUT': 500, } diff --git a/requirements/prod.txt b/requirements/prod.txt index a49fc6cd1b..70fd1019a9 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -17,7 +17,7 @@ Django==1.4.8 dj-database-url==0.2.2 django-aesfield==0.1 django-browserid==0.8 -django-cache-machine==0.6 +django-cache-machine==0.8 django-celery==3.0.17 django-cronjobs==0.2.3 django_csp==1.0.2 diff --git a/scripts/build.sh b/scripts/build.sh index 66a706252f..4399c7ba00 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -80,7 +80,7 @@ DATABASES['default']['TEST_CHARSET'] = 'utf8' DATABASES['default']['TEST_COLLATION'] = 'utf8_general_ci' CACHES = { 'default': { - 'BACKEND': 'caching.backends.locmem.CacheClass', + 'BACKEND': 'caching.backends.locmem.LocMemCache', } } CELERY_ALWAYS_EAGER = True diff --git a/scripts/run_jstests.sh b/scripts/run_jstests.sh index 634241d188..faf1921d2b 100755 --- a/scripts/run_jstests.sh +++ b/scripts/run_jstests.sh @@ -70,7 +70,7 @@ DATABASES = { CACHES = { 'default': { - 'BACKEND': 'caching.backends.locmem.CacheClass', + 'BACKEND': 'caching.backends.locmem.LocMemCache', } } CELERY_ALWAYS_EAGER = True diff --git a/scripts/run_mkt_tests.sh b/scripts/run_mkt_tests.sh index 7555888adf..7c9e4c8466 100755 --- a/scripts/run_mkt_tests.sh +++ b/scripts/run_mkt_tests.sh @@ -75,7 +75,7 @@ DATABASES['default']['TEST_CHARSET'] = 'utf8' DATABASES['default']['TEST_COLLATION'] = 'utf8_general_ci' CACHES = { 'default': { - 'BACKEND': 'caching.backends.locmem.CacheClass', + 'BACKEND': 'caching.backends.locmem.LocMemCache', } } CELERY_ALWAYS_EAGER = True diff --git a/settings_test.py b/settings_test.py index e1af22aa93..461b35e1bc 100644 --- a/settings_test.py +++ b/settings_test.py @@ -71,10 +71,14 @@ USERPICS_URL = STATIC_URL + '/img/uploads/userpics/%s/%s/%s.png?modified=%d' CACHES = { 'default': { - 'BACKEND': 'caching.backends.locmem.CacheClass', + 'BACKEND': 'caching.backends.locmem.LocMemCache', } } +# COUNT() caching can't be invalidated, it just expires after x seconds. This +# is just too annoying for tests, so disable it. +CACHE_COUNT_TIMEOUT = None + # No more failures! APP_PREVIEW = False diff --git a/sites/altdev/settings_base.py b/sites/altdev/settings_base.py index 6bc4c8da6e..975d4284e1 100644 --- a/sites/altdev/settings_base.py +++ b/sites/altdev/settings_base.py @@ -46,7 +46,7 @@ SLAVE_DATABASES = ['slave'] CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', # 'BACKEND': 'memcachepool.cache.UMemcacheCache', 'LOCATION': splitstrip(private.CACHES_DEFAULT_LOCATION), diff --git a/sites/dev/settings_base.py b/sites/dev/settings_base.py index 687942f873..ab2d552166 100644 --- a/sites/dev/settings_base.py +++ b/sites/dev/settings_base.py @@ -47,7 +47,7 @@ SLAVE_DATABASES = ['slave'] CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', 'LOCATION': splitstrip(private.CACHES_DEFAULT_LOCATION), 'TIMEOUT': 500, 'KEY_PREFIX': CACHE_PREFIX, diff --git a/sites/landfill/settings_base.py b/sites/landfill/settings_base.py index 5045224ba9..127aea75ae 100644 --- a/sites/landfill/settings_base.py +++ b/sites/landfill/settings_base.py @@ -46,7 +46,7 @@ SLAVE_DATABASES = ['slave'] CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', # 'BACKEND': 'memcachepool.cache.UMemcacheCache', 'LOCATION': splitstrip(private.CACHES_DEFAULT_LOCATION), diff --git a/sites/prod/settings_base.py b/sites/prod/settings_base.py index 5047e44aaa..5f04c2aea7 100644 --- a/sites/prod/settings_base.py +++ b/sites/prod/settings_base.py @@ -37,7 +37,7 @@ SLAVE_DATABASES = ['slave'] CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', 'LOCATION': splitstrip(private.CACHES_DEFAULT_LOCATION), 'TIMEOUT': 500, 'KEY_PREFIX': CACHE_PREFIX, diff --git a/sites/stage/settings_base.py b/sites/stage/settings_base.py index ff2bc516a3..a98d503aac 100644 --- a/sites/stage/settings_base.py +++ b/sites/stage/settings_base.py @@ -44,7 +44,7 @@ SLAVE_DATABASES = ['slave'] CACHES = { 'default': { - 'BACKEND': 'caching.backends.memcached.CacheClass', + 'BACKEND': 'caching.backends.memcached.MemcachedCache', # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', # 'BACKEND': 'memcachepool.cache.UMemcacheCache', 'LOCATION': splitstrip(private.CACHES_DEFAULT_LOCATION),