"""Invalidates the memory cache"""
xbmcgui.Window(xbmcgui.getCurrentWindowId()).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(xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty('memcache'))
- return cache_id in cached_items.keys()
-
def get_cached_item (self, cache_id):
"""Returns an item from the in memory cache
Contents of the requested cache item or none
"""
cached_items = pickle.loads(xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty('memcache'))
- if self.has_cached_item(cache_id) != True:
- return None
- return cached_items[cache_id]
+
+ return cached_items.get(cache_id)
def add_cached_item (self, cache_id, contents):
"""Adds an item to the in memory cache
"""
url_values = urllib.urlencode(params)
# check for cached items
- if self.kodi_helper.has_cached_item(cache_id=url_values) and params.get('cache', False) == True:
- self.log(msg='Fetching item from cache: (cache_id=' + url_values + ')')
- return self.kodi_helper.get_cached_item(cache_id=url_values)
+ if params.get('cache', False) == True:
+ cached_value = self.kodi_helper.get_cached_item(cache_id=url_values)
+
+ # Cache lookup successful?
+ if cached_value != None:
+ self.log(msg='Fetched item from cache: (cache_id=' + url_values + ')')
+ return cached_value
+
url = self.get_netflix_service_url()
full_url = url + '?' + url_values
data = urllib2.urlopen(full_url).read()