Little optimisation for E5Cache.

Sun, 15 Oct 2017 17:21:20 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 15 Oct 2017 17:21:20 +0200
changeset 5903
7e7002215f9e
parent 5902
fb4b68592b7c
child 5904
2ff6078532c0

Little optimisation for E5Cache.

E5Utilities/E5Cache.py file | annotate | diff | comparison | revisions
--- a/E5Utilities/E5Cache.py	Sat Oct 14 20:08:47 2017 +0200
+++ b/E5Utilities/E5Cache.py	Sun Oct 15 17:21:20 2017 +0200
@@ -10,6 +10,7 @@
 from __future__ import unicode_literals
 
 
+# TODO: add timeout for cached entries
 class E5Cache(object):
     """
     Class implementing a LRU cache of a specific size.
@@ -50,13 +51,14 @@
         """
         Private method to adjust the cache to its size.
         """
-        while len(self.__keyList) > self.__size:
-            key = self.__keyList.pop(0)
+        removeList, self.__keyList = \
+            self.__keyList[:-self.__size], self.__keyList[-self.__size:]
+        for key in removeList:
             del self.__store[key]
     
     def getSize(self):
         """
-        Public method to get the size of the cache.
+        Public method to get the maximum size of the cache.
         
         @return maximum number of entries of the cache
         @rtype int
@@ -65,7 +67,7 @@
     
     def setSize(self, newSize):
         """
-        Public method to change the size of the cache.
+        Public method to change the maximum size of the cache.
         
         @param newSize maximum number of entries that may be stored in the
             cache

eric ide

mercurial