Skip to content

Commit

Permalink
Use CACHALOT_TIMEOUT in 3 remaining places.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Sep 6, 2016
1 parent 571e6ec commit 522b5af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cachalot/transaction.py
Expand Up @@ -2,6 +2,8 @@

from __future__ import unicode_literals

from .settings import cachalot_settings


class AtomicCache(dict):
def __init__(self, parent_cache, db_alias):
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions cachalot/utils.py
Expand Up @@ -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)
Expand Down

0 comments on commit 522b5af

Please sign in to comment.