use cache.delete a) with an actual key and b) only on delete

This commit is contained in:
Martin Zimmermann 2013-11-01 17:02:08 +01:00
parent b3b26c1117
commit c5d52721c4

View File

@ -166,7 +166,6 @@ def single(app, environ, request, id):
for key in set(rv.keys()) - FIELDS: for key in set(rv.keys()) - FIELDS:
rv.pop(key) rv.pop(key)
app.cache.delete('hash', id)
logger.info('comment %i edited: %s', id, json.dumps(rv)) logger.info('comment %i edited: %s', id, json.dumps(rv))
checksum = hashlib.md5(rv["text"].encode('utf-8')).hexdigest() checksum = hashlib.md5(rv["text"].encode('utf-8')).hexdigest()
@ -178,12 +177,14 @@ def single(app, environ, request, id):
if request.method == 'DELETE': if request.method == 'DELETE':
item = app.db.comments.get(id)
app.cache.delete('hash', item['email'] or item['remote_addr'])
rv = app.db.comments.delete(id) rv = app.db.comments.delete(id)
if rv: if rv:
for key in set(rv.keys()) - FIELDS: for key in set(rv.keys()) - FIELDS:
rv.pop(key) rv.pop(key)
app.cache.delete('hash', id)
logger.info('comment %i deleted', id) logger.info('comment %i deleted', id)
resp = Response(json.dumps(rv), 200, content_type='application/json') resp = Response(json.dumps(rv), 200, content_type='application/json')