+ def setup_memcache (self):
+ """Sets up the memory cache if not existant"""
+ cached_items = self.win.getProperty('memcache')
+ # no cache setup yet, create one
+ if len(cached_items) < 1:
+ self.win.setProperty('memcache', pickle.dumps({}))
+
+ def invalidate_memcache (self):
+ """Invalidates the memory cache"""
+ self.win.setProperty('memcache', pickle.dumps({}))
+
+ def has_cached_item (self, cache_id):
+ """Checks if the requested item is in memory cache
+
+ Parameters
+ ----------
+ cache_id : :obj:`str`
+ ID of the cache entry
+
+ Returns
+ -------
+ bool
+ Item is cached
+ """
+ cached_items = pickle.loads(self.win.getProperty('memcache'))
+ return cache_id in cached_items.keys()
+
+ def get_cached_item (self, cache_id):
+ """Returns an item from the in memory cache
+
+ Parameters
+ ----------
+ cache_id : :obj:`str`
+ ID of the cache entry
+
+ Returns
+ -------
+ mixed
+ Contents of the requested cache item or none
+ """
+ cached_items = pickle.loads(self.win.getProperty('memcache'))
+ if self.has_cached_item(cache_id) != True:
+ return None
+ return cached_items[cache_id]
+
+ def add_cached_item (self, cache_id, contents):
+ """Adds an item to the in memory cache
+
+ Parameters
+ ----------
+ cache_id : :obj:`str`
+ ID of the cache entry
+
+ contents : mixed
+ Cache entry contents
+ """
+ cached_items = pickle.loads(self.win.getProperty('memcache'))
+ cached_items.update({cache_id: contents})
+ self.win.setProperty('memcache', pickle.dumps(cached_items))
+