diff --git a/cachalot/transaction.py b/cachalot/transaction.py index f75309c29..868c60a0c 100644 --- a/cachalot/transaction.py +++ b/cachalot/transaction.py @@ -2,6 +2,8 @@ from __future__ import unicode_literals +from .settings import cachalot_settings + class AtomicCache(dict): def __init__(self, parent_cache, db_alias): @@ -24,7 +26,9 @@ def set_many(self, data, timeout): self.update(data) def commit(self): - self.parent_cache.set_many(self, None) + if self: + self.parent_cache.set_many( + self, cachalot_settings.CACHALOT_TIMEOUT) # The previous `set_many` is not enough. The parent cache needs to be # invalidated in case another transaction occurred in the meantime. _invalidate_tables(self.parent_cache, self.db_alias, diff --git a/cachalot/utils.py b/cachalot/utils.py index 7417d4534..f54a0b4d1 100644 --- a/cachalot/utils.py +++ b/cachalot/utils.py @@ -163,14 +163,16 @@ def _get_table_cache_keys(compiler): def _invalidate_tables(cache, db_alias, tables): now = time() cache.set_many( - {_get_table_cache_key(db_alias, t): now for t in tables}, None) + {_get_table_cache_key(db_alias, t): now for t in tables}, + cachalot_settings.CACHALOT_TIMEOUT) if isinstance(cache, AtomicCache): cache.to_be_invalidated.update(tables) def _invalidate_table(cache, db_alias, table): - cache.set(_get_table_cache_key(db_alias, table), time(), None) + cache.set(_get_table_cache_key(db_alias, table), time(), + cachalot_settings.CACHALOT_TIMEOUT) if isinstance(cache, AtomicCache): cache.to_be_invalidated.add(table)