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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user