From 6bb4f6b28c548d7aaf42e739feecdf79a9e915a8 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Tue, 13 Mar 2012 09:01:49 +0100 Subject: [PATCH] [entropy.db] EntropyRepository: validate Live cache against mtime() Scenario: Process A is writing to EntropyRepository, adding new package entries. Process B is reading from EntropyRepository, querying for the same package entries, for example by using retrieveKeySlot(). This method uses a dict-based cache to speed up things, but this should be invalidated also when the mtime() value changes. --- lib/entropy/db/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/entropy/db/__init__.py b/lib/entropy/db/__init__.py index 2e1716664..cbf5da432 100644 --- a/lib/entropy/db/__init__.py +++ b/lib/entropy/db/__init__.py @@ -538,6 +538,10 @@ class EntropyRepository(EntropyRepositoryBase): if self._db_path is None: raise AttributeError("valid database path needed") + # tracking mtime to validate repository Live cache as + # well. + self._cur_mtime = self.mtime() + # setup service interface self.__skip_checks = skipChecks @@ -738,6 +742,10 @@ class EntropyRepository(EntropyRepositoryBase): self._live_cacher.set(self._getLiveCacheKey() + key, value) def _getLiveCache(self, key): + mtime = self.mtime() + if self._cur_mtime != mtime: + self._cur_mtime = mtime + self._discardLiveCache() return self._live_cacher.get(self._getLiveCacheKey() + key) def __del__(self):