Skip to content

Instantly share code, notes, and snippets.

@kaedroho
Created February 13, 2019 16:04
Show Gist options
  • Save kaedroho/cefd778ff5ea85166ded1ef817c62c6d to your computer and use it in GitHub Desktop.
Save kaedroho/cefd778ff5ea85166ded1ef817c62c6d to your computer and use it in GitHub Desktop.
from contextlib import contextmanager
from django.core.cache import caches
from django.core.cache.backends.dummy import DummyCache
class AlwaysDummyCache:
def __getitem__(self, key):
return DummyCache(None)
@contextmanager
def disable_caches():
caches = caches._caches.caches
caches._caches.caches = AlwaysDummyCache()
try:
yield
finally:
caches._caches.caches = caches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment