do not cleanup disco cache while windows is opened, clean it when we close window. Fixes #2490

This commit is contained in:
Yann Leboulanger 2006-10-05 11:26:41 +00:00
parent ce7e782054
commit f9abd2a86c
1 changed files with 17 additions and 4 deletions

View File

@ -121,6 +121,13 @@ class CacheDictionary:
def __call__(self): def __call__(self):
return self.value return self.value
def cleanup(self):
for key in self.cache.keys():
item = self.cache[key]
if item.source:
gobject.source_remove(item.source)
del self.cache[key]
def _expire_timeout(self, key): def _expire_timeout(self, key):
'''The timeout has expired, remove the object.''' '''The timeout has expired, remove the object.'''
if key in self.cache: if key in self.cache:
@ -132,8 +139,9 @@ class CacheDictionary:
item = self.cache[key] item = self.cache[key]
if item.source: if item.source:
gobject.source_remove(item.source) gobject.source_remove(item.source)
source = gobject.timeout_add(self.lifetime, self._expire_timeout, key) if self.lifetime:
item.source = source source = gobject.timeout_add(self.lifetime, self._expire_timeout, key)
item.source = source
def __getitem__(self, key): def __getitem__(self, key):
item = self.cache[key] item = self.cache[key]
@ -205,10 +213,14 @@ class ServicesCache:
ServiceCache instance.''' ServiceCache instance.'''
def __init__(self, account): def __init__(self, account):
self.account = account self.account = account
self._items = CacheDictionary(1, getrefresh = True) self._items = CacheDictionary(0, getrefresh = False)
self._info = CacheDictionary(1, getrefresh = True) self._info = CacheDictionary(0, getrefresh = False)
self._cbs = {} self._cbs = {}
def cleanup(self):
self._items.cleanup()
self._info.cleanup()
def _clean_closure(self, cb, type, addr): def _clean_closure(self, cb, type, addr):
# A closure died, clean up # A closure died, clean up
cbkey = (type, addr) cbkey = (type, addr)
@ -584,6 +596,7 @@ _('Without a connection, you can not browse available services'))
self.browser = None self.browser = None
self.window.destroy() self.window.destroy()
self.cache.cleanup()
for child in self.children[:]: for child in self.children[:]:
child.parent = None child.parent = None
if chain: if chain: