[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.
This commit is contained in:
Fabio Erculiani
2012-03-13 09:01:49 +01:00
parent 40343d0719
commit 6bb4f6b28c

View File

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