Removed all uses of create_cache.

Refactored the cache tests significantly.

Made it safe to override the CACHES setting.
This commit is contained in:
Aymeric Augustin 2013-11-23 14:19:48 +01:00
parent 35e289fe92
commit 905a74f52b
4 changed files with 520 additions and 520 deletions

View File

@ -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 @@ class Command(BaseCommand):
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)

View File

@ -46,7 +46,7 @@ More details about how the caching works:
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 @@ class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware):
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]

View File

@ -1,5 +1,6 @@
import os
import time
import threading
import warnings
from django.conf import settings
@ -19,6 +20,13 @@ setting_changed = Signal(providing_args=["setting", "value", "enter"])
COMPLEX_OVERRIDE_SETTINGS = set(['DATABASES'])
@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':

1024
tests/cache/tests.py vendored

File diff suppressed because it is too large Load Diff