[pyatspi2] Added a LRU cache for objects that use the soft cache



commit fa67398c8efe85d5ff584a305a3ae6c2304b0683
Author: Mike Gorse <mgorse novell com>
Date:   Thu Oct 7 16:30:52 2010 +0200

    Added a LRU cache for objects that use the soft cache

 pyatspi/accessible.py |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/pyatspi/accessible.py b/pyatspi/accessible.py
index 00582c1..194d842 100644
--- a/pyatspi/accessible.py
+++ b/pyatspi/accessible.py
@@ -207,6 +207,8 @@ class Accessible(BaseProxy):
         The interface which is implemented by all accessible objects.
         """
 
+        softLRU = []
+
         def __init__(self, cache, *args):
                 BaseProxy.__init__(self, *args);
 
@@ -549,8 +551,16 @@ class Accessible(BaseProxy):
         def getSoftCacheItem(self, name, func):
                 if not(name in self._soft_cache_data):
                         self._soft_cache_data[name] = func()
+                self.addLRU()
                 return self._soft_cache_data[name]
 
+        def addLRU(self):
+                if self in Accessible.softLRU:
+                        Accessible.softLRU.remove(self)
+                if len(Accessible.softLRU) == 20:
+                        Accessible.softLRU.remove (Accessible.softLRU[0])
+                Accessible.softLRU.append(self)
+
         def getSoftCacheProperty(self, interface, name):
                 if not((interface, name) in self._soft_cache_data):
                         self._soft_cache_data[(interface, name)] = self._pgetter(interface, name)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]