Exemplo n.º 1
0
 def __call__(self, *args):
     """
     Attempts to return the results of this function call from the cache;
     if it can't find it, then it will execute the function and add it to the
     cache.
     """
     from spyral import director
     frame = director.get_tick()
     if director.get_scene() is not self.scene:
         self.scene = director.get_scene()
         self.cache = {}
     if frame - self.last_clear > 100:
         for key, value in self.cache.items():
             data, oldframe = value
             if frame - oldframe > 250:
                 self.cache.pop(key)
         self.last_clear = frame
     try:
         data, oldframe = self.cache[args]
         self.cache[args] = (data, frame)
         return data
     except KeyError:
         res = self.func(*args)
         self.cache[args] = (res, frame)
         return res
     except TypeError:
         print ("WARNING: Unhashable type passed to SmartMemoize."
                "Reconsider using this decorator")
         return self.func(*args)
Exemplo n.º 2
0
 def __call__(self, *args):
     from spyral import director
     frame = director.get_tick()
     if director.get_scene() is not self.scene:
         self.scene = director.get_scene()
         self.cache = {}
     if frame - self.last_clear > 100:
         self.cache = dict((key,value) for key,value in self.cache.items() if frame - value[1] > 250)
         self.last_clear = frame
     try:
         data, oldframe = self.cache[args]
         self.cache[args] = (data, frame)
         return data
     except KeyError:
         res = self.func(*args)
         self.cache[args] = (res, frame)
         return res
     except TypeError:
         print("WARNING: Unhashable type passed to memoize2. Reconsider using this decorator")
         return self.func(*args)
Exemplo n.º 3
0
 def __call__(self, *args):
     from spyral import director
     frame = director.get_tick()
     if director.get_scene() is not self.scene:
         self.scene = director.get_scene()
         self.cache = {}
     if frame - self.last_clear > 100:
         for key, value in self.cache.items():
             data, oldframe = value
             if frame - oldframe > 250:
                 self.cache.pop(key)
         self.last_clear = frame
     try:
         data, oldframe = self.cache[args]
         self.cache[args] = (data, frame)
         return data
     except KeyError:
         res = self.func(*args)
         self.cache[args] = (res, frame)
         return res
     except TypeError:
         print "WARNING: Unhashable type passed to memoize2. Reconsider using this decorator"
         return self.func(*args)