From 2cda3c591e99be21005fc80158b0734bcd450a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 4 Dec 2008 18:25:58 +0100 Subject: [PATCH] Improve Cache when function return None or False --- trytond/tools/misc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/trytond/tools/misc.py b/trytond/tools/misc.py index 56da2906f2..2a3a80e0db 100644 --- a/trytond/tools/misc.py +++ b/trytond/tools/misc.py @@ -251,6 +251,7 @@ class Cache(object): def cached_result(self2, cursor=None, *args, **kwargs): result = None + find = False if isinstance(cursor, basestring): Cache.reset(cursor, self.name) self.lock.acquire() @@ -298,10 +299,11 @@ class Cache(object): mintime = time.time() - self.timeout if self.timeout <= 0 or mintime <= last_time: result = value + find = True finally: self.lock.release() - if not result: + if not find: # Work out new value, cache it and return it # Should copy() this value to avoid futur modf of the cacle ? result = function(self2, cursor, **dict(kwargs))