Permalink
Browse files

Removed all uses of create_cache.

Refactored the cache tests significantly.

Made it safe to override the CACHES setting.
  • Loading branch information...
1 parent 35e289f commit 905a74f52b24a198f802520ff06290a94dedc687 @aaugustin aaugustin committed Nov 23, 2013
Showing with 531 additions and 531 deletions.
  1. +2 −2 django/core/management/commands/createcachetable.py
  2. +2 −2 django/middleware/cache.py
  3. +8 −0 django/test/signals.py
  4. +519 −527 tests/cache/tests.py
@@ -1,7 +1,7 @@
from optparse import make_option
from django.conf import settings
-from django.core.cache import create_cache
+from django.core.cache import caches
from django.core.cache.backends.db import BaseDatabaseCache
from django.core.management.base import BaseCommand, CommandError
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
@@ -30,7 +30,7 @@ def handle(self, *tablenames, **options):
self.create_table(db, tablename)
else:
for cache_alias in settings.CACHES:
- cache = create_cache(cache_alias)
+ cache = caches[cache_alias]
if isinstance(cache, BaseDatabaseCache):
self.create_table(db, cache._table)
@@ -46,7 +46,7 @@
import warnings
from django.conf import settings
-from django.core.cache import create_cache, caches, DEFAULT_CACHE_ALIAS
+from django.core.cache import caches, DEFAULT_CACHE_ALIAS
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers, get_max_age
@@ -196,4 +196,4 @@ def __init__(self, cache_timeout=None, cache_anonymous_only=None, **kwargs):
msg = "CACHE_MIDDLEWARE_ANONYMOUS_ONLY has been deprecated and will be removed in Django 1.8."
warnings.warn(msg, DeprecationWarning, stacklevel=1)
- self.cache = create_cache(self.cache_alias)
+ self.cache = caches[self.cache_alias]
@@ -1,5 +1,6 @@
import os
import time
+import threading
import warnings
from django.conf import settings
@@ -20,6 +21,13 @@
@receiver(setting_changed)
+def clear_cache_handlers(**kwargs):
+ if kwargs['setting'] == 'CACHES':
+ from django.core.cache import caches
+ caches._caches = threading.local()
+
+
+@receiver(setting_changed)
def update_connections_time_zone(**kwargs):
if kwargs['setting'] == 'TIME_ZONE':
# Reset process time zone
Oops, something went wrong. Retry.

0 comments on commit 905a74f

Please sign in to comment.