diff options
author | Rob Austein <sra@hactrn.net> | 2012-08-09 21:31:10 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2012-08-09 21:31:10 +0000 |
commit | 07d1098ee09b2743f11f2a66294f3288a6a5f2c2 (patch) | |
tree | 2a1fddcab36202c23d2c9da9fdbd961b45c8114c /rpkid/rpki/sql.py | |
parent | f1ea21697f9ea7deb771df7a3710189f46b1f597 (diff) |
Switch rpki.sql.session.cache to use weak references, so that Python's
garbage collector can free up cache entries we're not using for us.
Rework update_roas() to be a bit more frugal with memory. See #278.
svn path=/branches/tk274/; revision=4626
Diffstat (limited to 'rpkid/rpki/sql.py')
-rw-r--r-- | rpkid/rpki/sql.py | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/rpkid/rpki/sql.py b/rpkid/rpki/sql.py index 14d1e1fb..9d420c80 100644 --- a/rpkid/rpki/sql.py +++ b/rpkid/rpki/sql.py @@ -32,27 +32,27 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ +import weakref + from rpki.mysql_import import (MySQLdb, _mysql_exceptions) -import rpki.x509, rpki.resource_set, rpki.sundial, rpki.log +import rpki.x509 +import rpki.resource_set +import rpki.sundial +import rpki.log class session(object): """ SQL session layer. """ - ## @var clear_threshold - # Size above which .cache_clear_maybe() should clear the cache. - - clear_threshold = 5000 - def __init__(self, cfg): self.username = cfg.get("sql-username") self.database = cfg.get("sql-database") self.password = cfg.get("sql-password") - self.cache = {} + self.cache = weakref.WeakValueDictionary() self.dirty = set() self.connect() @@ -95,19 +95,13 @@ class session(object): def cache_clear(self): """ - Clear the object cache. + Clear the SQL object cache. Shouldn't be necessary now that the + cache uses weak references, but should be harmless. """ rpki.log.debug("Clearing SQL cache") self.assert_pristine() self.cache.clear() - def cache_clear_maybe(self): - """ - Clear the object cache if its size is above clear_threshold. - """ - if len(self.cache) >= self.clear_threshold: - self.cache_clear() - def assert_pristine(self): """ Assert that there are no dirty objects in the cache. |