Standardize cache_key generation
This commit is contained in:
1 parent
97c456c9e1
commit
6af00bf026
3 files changed
+9
-8
No files matched your search
@@ -259,8 +259,8 @@ class Plugin(object):
|
|||||||
|
|
||||||
|
|
||||||
def getCache(self, cache_key, url = None, **kwargs):
|
def getCache(self, cache_key, url = None, **kwargs):
|
||||||
cache_key = md5(ss(cache_key))
|
cache_key_md5 = md5(ss(cache_key))
|
||||||
cache = Env.get('cache').get(cache_key)
|
cache = Env.get('cache').get(cache_key_md5)
|
||||||
if cache:
|
if cache:
|
||||||
if not Env.get('dev'): log.debug('Getting cache %s', cache_key)
|
if not Env.get('dev'): log.debug('Getting cache %s', cache_key)
|
||||||
return cache
|
return cache
|
||||||
@@ -284,8 +284,9 @@ class Plugin(object):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
def setCache(self, cache_key, value, timeout = 300):
|
def setCache(self, cache_key, value, timeout = 300):
|
||||||
|
cache_key_md5 = md5(ss(cache_key))
|
||||||
log.debug('Setting cache %s', 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
|
return value
|
||||||
|
|
||||||
def createNzbName(self, data, movie):
|
def createNzbName(self, data, movie):
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Suggestion(Plugin):
|
|||||||
suggestions = cached_suggestion
|
suggestions = cached_suggestion
|
||||||
else:
|
else:
|
||||||
suggestions = fireEvent('movie.suggest', movies = movies, ignore = ignored, single = True)
|
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 {
|
return {
|
||||||
'success': True,
|
'success': True,
|
||||||
@@ -87,6 +87,6 @@ class Suggestion(Plugin):
|
|||||||
if suggestions:
|
if suggestions:
|
||||||
new_suggestions.extend(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
|
return new_suggestions
|
||||||
@@ -53,7 +53,7 @@ class TheMovieDb(MovieProvider):
|
|||||||
|
|
||||||
log.info('Found: %s', [result['titles'][0] + ' (' + str(result.get('year', 0)) + ')' for result in results])
|
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
|
return results
|
||||||
except SyntaxError, e:
|
except SyntaxError, e:
|
||||||
log.error('Failed to parse XML response: %s', e)
|
log.error('Failed to parse XML response: %s', e)
|
||||||
@@ -74,7 +74,7 @@ class TheMovieDb(MovieProvider):
|
|||||||
log.debug('Getting info: %s', cache_key)
|
log.debug('Getting info: %s', cache_key)
|
||||||
movie = tmdb3.Movie(identifier)
|
movie = tmdb3.Movie(identifier)
|
||||||
result = self.parseMovie(movie)
|
result = self.parseMovie(movie)
|
||||||
self.setCache(md5(ss(cache_key)), result)
|
self.setCache(cache_key, result)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class TheMovieDb(MovieProvider):
|
|||||||
movie_data['titles'] = list(set(movie_data['titles']))
|
movie_data['titles'] = list(set(movie_data['titles']))
|
||||||
|
|
||||||
# Cache movie parsed
|
# Cache movie parsed
|
||||||
self.setCache(md5(ss(cache_key)), movie_data)
|
self.setCache(cache_key, movie_data)
|
||||||
|
|
||||||
return movie_data
|
return movie_data
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user