Browse Source

Standardize cache_key generation

pull/2133/head
Ruud 12 years ago
parent
commit
6af00bf026
  1. 7
      couchpotato/core/plugins/base.py
  2. 4
      couchpotato/core/plugins/suggestion/main.py
  3. 6
      couchpotato/core/providers/info/themoviedb/main.py

7
couchpotato/core/plugins/base.py

@ -259,8 +259,8 @@ class Plugin(object):
def getCache(self, cache_key, url = None, **kwargs):
cache_key = md5(ss(cache_key))
cache = Env.get('cache').get(cache_key)
cache_key_md5 = md5(ss(cache_key))
cache = Env.get('cache').get(cache_key_md5)
if cache:
if not Env.get('dev'): log.debug('Getting cache %s', cache_key)
return cache
@ -284,8 +284,9 @@ class Plugin(object):
return ''
def setCache(self, cache_key, value, timeout = 300):
cache_key_md5 = md5(ss(cache_key))
log.debug('Setting cache %s', cache_key)
Env.get('cache').set(cache_key, value, timeout)
Env.get('cache').set(cache_key_md5, value, timeout)
return value
def createNzbName(self, data, movie):

4
couchpotato/core/plugins/suggestion/main.py

@ -35,7 +35,7 @@ class Suggestion(Plugin):
suggestions = cached_suggestion
else:
suggestions = fireEvent('movie.suggest', movies = movies, ignore = ignored, single = True)
self.setCache(md5(ss('suggestion_cached')), suggestions, timeout = 6048000) # Cache for 10 weeks
self.setCache('suggestion_cached', suggestions, timeout = 6048000) # Cache for 10 weeks
return {
'success': True,
@ -87,6 +87,6 @@ class Suggestion(Plugin):
if suggestions:
new_suggestions.extend(suggestions)
self.setCache(md5(ss('suggestion_cached')), new_suggestions, timeout = 6048000)
self.setCache('suggestion_cached', new_suggestions, timeout = 6048000)
return new_suggestions

6
couchpotato/core/providers/info/themoviedb/main.py

@ -53,7 +53,7 @@ class TheMovieDb(MovieProvider):
log.info('Found: %s', [result['titles'][0] + ' (' + str(result.get('year', 0)) + ')' for result in results])
self.setCache(md5(ss(cache_key)), results)
self.setCache(cache_key, results)
return results
except SyntaxError, e:
log.error('Failed to parse XML response: %s', e)
@ -74,7 +74,7 @@ class TheMovieDb(MovieProvider):
log.debug('Getting info: %s', cache_key)
movie = tmdb3.Movie(identifier)
result = self.parseMovie(movie)
self.setCache(md5(ss(cache_key)), result)
self.setCache(cache_key, result)
except:
pass
@ -135,7 +135,7 @@ class TheMovieDb(MovieProvider):
movie_data['titles'] = list(set(movie_data['titles']))
# Cache movie parsed
self.setCache(md5(ss(cache_key)), movie_data)
self.setCache(cache_key, movie_data)
return movie_data

Loading…
Cancel
Save