diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index 63b739f1dee..e5296814a3a 100644 --- a/django/core/cache/__init__.py +++ b/django/core/cache/__init__.py @@ -13,19 +13,17 @@ object. See docs/topics/cache.txt for information on the public API. """ from threading import local -import warnings from django.conf import settings from django.core import signals from django.core.cache.backends.base import ( InvalidCacheBackendError, CacheKeyWarning, BaseCache) from django.core.exceptions import ImproperlyConfigured -from django.utils.deprecation import RemovedInDjango19Warning from django.utils.module_loading import import_string __all__ = [ - 'get_cache', 'cache', 'DEFAULT_CACHE_ALIAS', 'InvalidCacheBackendError', + 'cache', 'DEFAULT_CACHE_ALIAS', 'InvalidCacheBackendError', 'CacheKeyWarning', 'BaseCache', ] @@ -35,33 +33,6 @@ if DEFAULT_CACHE_ALIAS not in settings.CACHES: raise ImproperlyConfigured("You must define a '%s' cache" % DEFAULT_CACHE_ALIAS) -def get_cache(backend, **kwargs): - """ - Function to create a cache backend dynamically. This is flexible by design - to allow different use cases: - - To load a backend that is pre-defined in the settings:: - - cache = get_cache('default') - - To create a backend with its dotted import path, - including arbitrary options:: - - cache = get_cache('django.core.cache.backends.memcached.MemcachedCache', **{ - 'LOCATION': '127.0.0.1:11211', 'TIMEOUT': 30, - }) - - """ - warnings.warn("'get_cache' is deprecated in favor of 'caches'.", - RemovedInDjango19Warning, stacklevel=2) - cache = _create_cache(backend, **kwargs) - # Some caches -- python-memcached in particular -- need to do a cleanup at the - # end of a request cycle. If not implemented in a particular backend - # cache.close is a no-op - signals.request_finished.connect(cache.close) - return cache - - def _create_cache(backend, **kwargs): try: # Try to get the CACHES entry for the given backend name first diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index bca0aa35a9a..70101ec9464 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -544,7 +544,7 @@ Cache * Access to caches configured in :setting:`CACHES` is now available via :data:`django.core.cache.caches`. This dict-like object provides a different - instance per thread. It supersedes :func:`django.core.cache.get_cache` which + instance per thread. It supersedes ``django.core.cache.get_cache()`` which is now deprecated. * If you instantiate cache backends directly, be aware that they aren't @@ -1468,7 +1468,7 @@ Features deprecated in 1.7 ``django.core.cache.get_cache`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -:func:`django.core.cache.get_cache` has been supplanted by +``django.core.cache.get_cache`` has been supplanted by :data:`django.core.cache.caches`. ``django.utils.dictconfig``/``django.utils.importlib`` diff --git a/docs/topics/cache.txt b/docs/topics/cache.txt index d62b9519eee..f638149b954 100644 --- a/docs/topics/cache.txt +++ b/docs/topics/cache.txt @@ -747,21 +747,6 @@ Accessing the cache This object is equivalent to ``caches['default']``. -.. function:: django.core.cache.get_cache(backend, **kwargs) - - .. deprecated:: 1.7 - This function has been deprecated in favor of - :data:`~django.core.cache.caches`. - - Before Django 1.7 this function was the canonical way to obtain a cache - instance. It could also be used to create a new cache instance with a - different configuration. - - >>> from django.core.cache import get_cache - >>> get_cache('default') - >>> get_cache('django.core.cache.backends.memcached.MemcachedCache', LOCATION='127.0.0.2') - >>> get_cache('default', TIMEOUT=300) - Basic usage ----------- diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 3e2dc5c1a04..db2edf5f266 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -17,9 +17,7 @@ import warnings from django.conf import settings from django.core import management from django.core import signals -from django.core.cache import (cache, caches, CacheKeyWarning, - InvalidCacheBackendError, DEFAULT_CACHE_ALIAS, get_cache, - close_caches) +from django.core.cache import cache, caches, CacheKeyWarning, DEFAULT_CACHE_ALIAS from django.db import connection, connections, transaction from django.core.cache.utils import make_template_fragment_key from django.http import HttpRequest, HttpResponse, StreamingHttpResponse @@ -30,14 +28,13 @@ from django.template import engines from django.template.context_processors import csrf from django.template.response import TemplateResponse from django.test import (TestCase, TransactionTestCase, RequestFactory, - ignore_warnings, override_settings) + override_settings) from django.test.signals import setting_changed from django.utils import six from django.utils import timezone from django.utils import translation from django.utils.cache import (patch_vary_headers, get_cache_key, learn_cache_key, patch_cache_control, patch_response_headers) -from django.utils.deprecation import RemovedInDjango19Warning from django.utils.encoding import force_text from django.views.decorators.cache import cache_page @@ -1221,40 +1218,13 @@ class CustomCacheKeyValidationTests(TestCase): } } ) -class GetCacheTests(TestCase): - - @ignore_warnings(category=RemovedInDjango19Warning) - def test_simple(self): - self.assertIsInstance( - caches[DEFAULT_CACHE_ALIAS], - get_cache('default').__class__ - ) - - cache = get_cache( - 'django.core.cache.backends.dummy.DummyCache', - **{'TIMEOUT': 120} - ) - self.assertEqual(cache.default_timeout, 120) - - self.assertRaises(InvalidCacheBackendError, get_cache, 'does_not_exist') +class CacheClosingTests(TestCase): def test_close(self): self.assertFalse(cache.closed) signals.request_finished.send(self.__class__) self.assertTrue(cache.closed) - @ignore_warnings(category=RemovedInDjango19Warning) - def test_close_deprecated(self): - cache = get_cache('cache.closeable_cache.CacheClass') - self.assertFalse(cache.closed) - # Ensure that we don't close the global cache instances. - signals.request_finished.disconnect(close_caches) - try: - signals.request_finished.send(self.__class__) - self.assertTrue(cache.closed) - finally: - signals.request_finished.connect(close_caches) - DEFAULT_MEMORY_CACHES_SETTINGS = { 'default': {