I noticed yestarday that when the key of a cached object (in this case
it was an SDL surface, IIRC) is containing non-ASCII data (e.g. TV
program description in Finnish, containing ä and ö characters),
retrieving the object from cache fails (and the requested object is not
displayed anymore).

Here is a quick-and-dirty fix (which consists in not caching objects
that provoke failures, and silently ignore the failures), but it would
be much better to find a way to cache any kind of data. With the current
approach (using index()), I have not found a solution.

Here is also the patch I wrote for avoiding errors, but I wouldn't put
it into the CVS, unless no other solution is found.

Matthieu
-- 
 (~._.~)        Matthieu Weber - Université de Jyväskylä         (~._.~)
  ( ? )                email : [EMAIL PROTECTED]                  ( ? ) 
 ()- -()               public key id : 452AE0AD                  ()- -()
 (_)-(_)  "Humor ist, wenn man trotzdem lacht (Germain Muller)"  (_)-(_)
Index: objectcache.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/objectcache.py,v
retrieving revision 1.2
diff -u -r1.2 objectcache.py
--- objectcache.py      24 Apr 2003 19:55:51 -0000      1.2
+++ objectcache.py      4 Jul 2003 06:20:44 -0000
@@ -61,22 +61,27 @@
         if not key in self.cache:
             return None
         else:
-            del self.lru[self.lru.index(key)]
-            self.lru.append(key)
-            return self.cache[key]
+            try:
+                del self.lru[self.lru.index(key)]
+                self.lru.append(key)
+                return self.cache[key]
+            except:
+                return None
 
 
     def __setitem__(self, key, object):
         # Do we need to delete the oldest item?
-        if len(self.cache) > self.cachesize:
-            # Yes
-            lru_key = self.lru[0]
-            del self.cache[lru_key]
-            del self.lru[0]
+        try:
+            if len(self.cache) > self.cachesize:
+                # Yes
+                lru_key = self.lru[0]
+                del self.cache[lru_key]
+                del self.lru[0]
 
-        self.cache[key] = object
-        self.lru.append(key)
-        
+            self.cache[key] = object
+            self.lru.append(key)
+        except:
+            pass
 
     def __delitem__(self, key):
         if not key in self.cache:

Reply via email to