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)
pull/644/head
Mike Fährmann 5 years ago
parent 380b693fad
commit 34887ae139
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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:

Loading…
Cancel
Save