From c4f104ae55846310d70aa913885607195489f09b Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Wed, 25 Jul 2012 17:22:21 +0000 Subject: Clean up SQL cache when it gets big, break up huge batches of ROA requests to avoid timeouts. See #274. svn path=/trunk/; revision=4607 --- rpkid/rpki/sql.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'rpkid/rpki/sql.py') diff --git a/rpkid/rpki/sql.py b/rpkid/rpki/sql.py index b6be65b6..14d1e1fb 100644 --- a/rpkid/rpki/sql.py +++ b/rpkid/rpki/sql.py @@ -41,6 +41,11 @@ 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") @@ -92,8 +97,17 @@ class session(object): """ Clear the object cache. """ + 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. -- cgit v1.2.3