Add more debug logs (refs #5586)

This commit is contained in:
Benjamin Dauvergne 2014-09-25 14:05:52 +02:00
parent a6419a4722
commit db31f6387d
1 changed files with 9 additions and 2 deletions

View File

@ -247,8 +247,8 @@ class Data(object):
return msg
return None
if self.refresh and data is not None:
log.debug('set cache for url %r with key %r', self.url, self.key)
cache.set(self.key, (data, self.now+self.refresh), 86400*12)
log.debug('finished')
if self.key in self.UPDATE_THREADS:
c = self.CONDITIONS.setdefault(self.key, threading.Condition())
with c:
@ -264,16 +264,22 @@ class Data(object):
return self.__content
self.__content, until = cache.get(self.key, (self.__CACHE_SENTINEL, None))
use_cache = self.__content is not self.__CACHE_SENTINEL
if not use_cache:
log.debug('found content in cache for url %r', self.url)
# do not use cache if refresh timeout is 0
use_cache = use_cache and self.refresh > 0
if self.refresh == 0:
log.debug('self refresh is 0, ignoring cache')
# do not use cache if updatecache is present in the query string
use_cache = use_cache and (not self.request or 'updatecache' not in self.request.GET)
if self.request and 'updatecache' not in self.request.GET:
log.debug('updatecache in query string, ignoring cache')
if use_cache:
if until < self.now:
# reload cache content asynchronously in a thread
# and return the current content
log.debug('stale content reloading')
log.debug('asynchronous update for url %r', self.url)
c = self.CONDITIONS.setdefault(self.key, threading.Condition())
t = threading.Thread(target=self.update_content)
t2 = self.UPDATE_THREADS.setdefault(self.key, t)
@ -288,6 +294,7 @@ class Data(object):
c.wait()
t2.join()
else:
log.debug('synchronous update for url %r', self.url)
self.__content = self.update_content()
return self.__content
content = property(get_content)