Use CACHALOT_TIMEOUT in 3 remaining places.

This commit is contained in:
Bertrand Bordage 2016-09-06 23:21:01 +02:00
parent 571e6ec691
commit 522b5af899
2 changed files with 9 additions and 3 deletions

View File

@ -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 @@ class AtomicCache(dict):
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,

View File

@ -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)