mirror of
https://github.com/django/django.git
synced 2025-10-09 18:12:39 +00:00
Fixed #33252 -- Made cache middlewares thread-safe.
This commit is contained in:
parent
0c05c183e4
commit
3ff7b15bb7
2 changed files with 23 additions and 3 deletions
15
tests/cache/tests.py
vendored
15
tests/cache/tests.py
vendored
|
@ -2488,6 +2488,21 @@ class CacheMiddlewareTest(SimpleTestCase):
|
|||
self.assertIn('Cache-Control', response)
|
||||
self.assertIn('Expires', response)
|
||||
|
||||
def test_per_thread(self):
|
||||
"""The cache instance is different for each thread."""
|
||||
thread_caches = []
|
||||
middleware = CacheMiddleware(empty_response)
|
||||
|
||||
def runner():
|
||||
thread_caches.append(middleware.cache)
|
||||
|
||||
for _ in range(2):
|
||||
thread = threading.Thread(target=runner)
|
||||
thread.start()
|
||||
thread.join()
|
||||
|
||||
self.assertIsNot(thread_caches[0], thread_caches[1])
|
||||
|
||||
|
||||
@override_settings(
|
||||
CACHE_MIDDLEWARE_KEY_PREFIX='settingsprefix',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue