From a504efc8a7138c615ef61724150c2e7deacda49b Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Wed, 17 Jun 2015 21:22:22 +0200 Subject: [PATCH] Simplification. --- cachalot/api.py | 6 +++++- cachalot/cache.py | 8 -------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cachalot/api.py b/cachalot/api.py index a01f478..0bf1c2c 100644 --- a/cachalot/api.py +++ b/cachalot/api.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.conf import settings +from django.db import connections from .cache import cachalot_caches from .utils import _get_table_cache_key, _invalidate_table_cache_keys @@ -84,4 +85,7 @@ def invalidate_all(cache_alias=None, db_alias=None): """ for cache_alias, db_alias in _aliases_iterator(cache_alias, db_alias): - cachalot_caches.invalidate_all(cache_alias, db_alias) + tables = connections[db_alias].introspection.table_names() + table_cache_keys = [_get_table_cache_key(db_alias, t) for t in tables] + _invalidate_table_cache_keys(cachalot_caches.get_cache(cache_alias), + table_cache_keys) diff --git a/cachalot/cache.py b/cachalot/cache.py index 3b098f1..d967346 100644 --- a/cachalot/cache.py +++ b/cachalot/cache.py @@ -5,11 +5,9 @@ from threading import local # TODO: Replace with caches[CACHALOT_CACHE] when we drop Django 1.6 support. from django.core.cache import get_cache as get_django_cache -from django.db import connections from .settings import cachalot_settings from .transaction import AtomicCache -from .utils import _get_table_cache_key, _invalidate_table_cache_keys class CacheHandler(local): @@ -43,11 +41,5 @@ class CacheHandler(local): for atomic_cache in atomic_caches: atomic_cache.commit() - def invalidate_all(self, cache_alias, db_alias): - tables = connections[db_alias].introspection.table_names() - table_cache_keys = [_get_table_cache_key(db_alias, t) for t in tables] - _invalidate_table_cache_keys(cachalot_caches.get_cache(cache_alias), - table_cache_keys) - cachalot_caches = CacheHandler()