diff options
author | Rob Austein <sra@hactrn.net> | 2012-07-25 17:22:21 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2012-07-25 17:22:21 +0000 |
commit | c4f104ae55846310d70aa913885607195489f09b (patch) | |
tree | 585491945887936cbc0f96d46ba41d62cc4db402 /rpkid/rpki/sql.py | |
parent | f932750ba2594758c681a771e0dafd34e6b53ae1 (diff) |
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
Diffstat (limited to 'rpkid/rpki/sql.py')
-rw-r--r-- | rpkid/rpki/sql.py | 14 |
1 files changed, 14 insertions, 0 deletions
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. |