From 267b9153a37c725b8fba81cb6fe7a7f614da4d2f Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 6 Sep 2011 17:37:18 +0100 Subject: [PATCH] Added function to purge stale cache documents --- apishiv/cache.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apishiv/cache.py b/apishiv/cache.py index 34f29ae..57e19ab 100644 --- a/apishiv/cache.py +++ b/apishiv/cache.py @@ -75,3 +75,12 @@ class DbCacheHandler: self.disconnect() except sqlite3.Error as e: self.log.error("Error storing document: %s", e.args[0]) + + def purge_stale(self): + self.log.info("Purging stale cached documents") + try: + self.cursor.execute("DELETE FROM api_cache WHERE datetime(cacheduntil, 'unixepoch') >= current_timestamp") + self.conn.commit() + self.disconnect() + except sqlite3.Error as e: + self.log.error("Error purging document cache: %s", e.args[0])