Previously we used to load the cache once to check if the requested
item was in there, and then another time to actually load it.
Combine both functions into one for less overhead.
Signed-off-by: s.golasch <s.golasch@telekom.de>
"""Invalidates the memory cache"""
xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty('memcache', pickle.dumps({}))
"""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
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'))
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
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
"""
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()
url = self.get_netflix_service_url()
full_url = url + '?' + url_values
data = urllib2.urlopen(full_url).read()