aboutsummaryrefslogtreecommitdiff
path: root/rpkid/rpki/sql.py
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid/rpki/sql.py')
-rw-r--r--rpkid/rpki/sql.py14
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.