fix bugs in DatabaseCacheDecorator.update()/.invalidate()

- call db.commit() after changes have been made
- remove 'LIMIT 1' from the DELETE statement in invalidate()
    (only available if SQLite3 was compiled with the right flags
     enabled, syntax error otherwise)
This commit is contained in:
Mike Fährmann
2020-02-23 20:59:16 +01:00
parent 380b693fad
commit 34887ae139

View File

@@ -126,20 +126,26 @@ class DatabaseCacheDecorator():
def update(self, key, value):
expires = int(time.time()) + self.maxage
self.cache[key] = value, expires
self.cursor().execute(
"INSERT OR REPLACE INTO data VALUES (?,?,?)",
("%s-%s" % (self.key, key), pickle.dumps(value), expires),
)
try:
self.cursor().execute(
"INSERT OR REPLACE INTO data VALUES (?,?,?)",
("%s-%s" % (self.key, key), pickle.dumps(value), expires),
)
finally:
self.db.commit()
def invalidate(self, key):
try:
del self.cache[key]
except KeyError:
pass
self.cursor().execute(
"DELETE FROM data WHERE key=? LIMIT 1",
("%s-%s" % (self.key, key),),
)
try:
self.cursor().execute(
"DELETE FROM data WHERE key=?",
("%s-%s" % (self.key, key),),
)
finally:
self.db.commit()
def cursor(self):
if self._init: