summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-12-10 09:36:40 +0000
committerZac Medico <zmedico@gentoo.org>2006-12-10 09:36:40 +0000
commit2783820d4f2b1c0649efdd64b775b7f2a1f7d48d (patch)
tree6958a445f16bb52ad03bc0a29c11d3b5b0d7febc
parent238b0337a47208fd72f24a7ba51aa0bcceeb858b (diff)
downloadportage-2783820d4f2b1c0649efdd64b775b7f2a1f7d48d.tar.gz
portage-2783820d4f2b1c0649efdd64b775b7f2a1f7d48d.tar.bz2
portage-2783820d4f2b1c0649efdd64b775b7f2a1f7d48d.zip
Cache the results of fakedbapi.match() calls and clear the cache automatically when necessary.
svn path=/main/trunk/; revision=5253
-rw-r--r--pym/portage.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 7b0d17cc0..67debcd5f 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -4370,6 +4370,19 @@ class fakedbapi(dbapi):
if settings is None:
settings = globals()["settings"]
self.settings = settings
+ self._match_cache = {}
+
+ def _clear_cache(self):
+ if self._match_cache:
+ self._match_cache = {}
+
+ def match(self, origdep, use_cache=1):
+ result = self._match_cache.get(origdep, None)
+ if result is not None:
+ return result[:]
+ result = dbapi.match(self, origdep, use_cache=use_cache)
+ self._match_cache[origdep] = result
+ return result[:]
def cpv_exists(self,mycpv):
return self.cpvdict.has_key(mycpv)
@@ -4391,6 +4404,7 @@ class fakedbapi(dbapi):
def cpv_inject(self, mycpv, metadata=None):
"""Adds a cpv from the list of available packages."""
+ self._clear_cache()
mycp=cpv_getkey(mycpv)
self.cpvdict[mycpv] = metadata
myslot = None
@@ -4422,6 +4436,7 @@ class fakedbapi(dbapi):
def cpv_remove(self,mycpv):
"""Removes a cpv from the list of available packages."""
+ self._clear_cache()
mycp=cpv_getkey(mycpv)
if self.cpvdict.has_key(mycpv):
del self.cpvdict[mycpv]
@@ -4441,6 +4456,7 @@ class fakedbapi(dbapi):
return [metadata.get(x, "") for x in wants]
def aux_update(self, cpv, values):
+ self._clear_cache()
self.cpvdict[cpv].update(values)
class bindbapi(fakedbapi):