Repository: Flexget/Flexget

Issue:
Cache time expired exception from configure_series plugin
Hello,

I'm running Flexget 1.2.481 and received the following crash report:

```
2016-03-14 23:19 CRITICAL task         <task name>         BUG: Unhandled error in plugin configure_series: (u'trakt_list_77ef1f69b4d443524da29986991b3510', u'cache time expired')
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 438, in __run_plugin
    return method(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 22, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/plugin_configure_series.py", line 69, in on_task_start
    result = method(task, input_config)
  File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 22, in __call__
    return self.func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flexget/utils/cached_input.py", line 115, in wrapped_func
    for entry in self.cache[cache_name]:
  File "/usr/local/lib/python2.7/dist-packages/flexget/utils/tools.py", line 428, in __getitem__
    self._last_prune = datetime.now()
KeyError: (u'trakt_list_77ef1f69b4d443524da29986991b3510', u'cache time expired')
```

Here's what I believe to be the relevant portion of my config file:

``` yaml
templates:
  tv:
    # Discover which TV series should be downloaded from trakt.tv.
    configure_series:
      settings:
        quality: "720p+ hdtv+"
        identified_by: "ep"
        propers: no

      from:
        trakt_list:
          username: "{{ secrets.trakt.username }}"
          account: "{{ secrets.trakt.username }}"
          list: "{{ secrets.trakt.list }}"
          type: "shows"

          # Don't include the year at the end of series names.
          strip_dates: yes
```



Discussion:

Resolving patch:
diff --git a/flexget/plugins/filter/exists_movie.py b/flexget/plugins/filter/exists_movie.py
--- a/flexget/plugins/filter/exists_movie.py
+++ b/flexget/plugins/filter/exists_movie.py
@@ -82,9 +82,10 @@ def on_task_filter(self, task, config):
         for folder in config['path']:
             folder = Path(folder).expanduser()
             # see if this path has already been scanned
-            if folder in self.cache:
+            cached_qualities = self.cache.get(folder, None)
+            if cached_qualities:
                 log.verbose('Using cached scan for %s ...' % folder)
-                qualities.update(self.cache[folder])
+                qualities.update(cached_qualities)
                 continue
 
             path_ids = {}
diff --git a/flexget/plugins/plugin_cookies.py b/flexget/plugins/plugin_cookies.py
--- a/flexget/plugins/plugin_cookies.py
+++ b/flexget/plugins/plugin_cookies.py
@@ -135,19 +135,22 @@ def on_task_start(self, task, config):
         config = self.prepare_config(config)
         cookie_type = config.get('type')
         cookie_file = os.path.expanduser(config.get('file'))
-        if cookie_file in self.cookiejars:
+        cj = self.cookiejars.get(cookie_file, None)
+        if cj is not None:
             log.debug('Loading cookiejar from cache.')
-            cj = self.cookiejars[cookie_file]
         elif cookie_type == 'firefox3':
             log.debug('Loading %s cookies' % cookie_type)
             cj = self.sqlite2cookie(cookie_file)
+            self.cookiejars[cookie_file] = cj
         else:
             if cookie_type == 'mozilla':
                 log.debug('Loading %s cookies' % cookie_type)
                 cj = cookielib.MozillaCookieJar()
+                self.cookiejars[cookie_file] = cj
             elif cookie_type == 'lwp':
                 log.debug('Loading %s cookies' % cookie_type)
                 cj = cookielib.LWPCookieJar()
+                self.cookiejars[cookie_file] = cj
             else:
                 raise plugin.PluginError('Unknown cookie type %s' % cookie_type, log)
 
@@ -158,9 +161,6 @@ def on_task_start(self, task, config):
                 import sys
                 raise plugin.PluginError('Cookies could not be loaded: %s' % sys.exc_info()[1], log)
 
-        if cookie_file not in self.cookiejars:
-            self.cookiejars[cookie_file] = cj
-
         # Add cookiejar to our requests session
         task.requests.add_cookiejar(cj)
         # Add handler to urllib2 default opener for backwards compatibility
diff --git a/flexget/utils/cached_input.py b/flexget/utils/cached_input.py
--- a/flexget/utils/cached_input.py
+++ b/flexget/utils/cached_input.py
@@ -108,11 +108,13 @@ def wrapped_func(*args, **kwargs):
             cache_name = self.name + '_' + hash
             log.debug('cache name: %s (has: %s)' % (cache_name, ', '.join(self.cache.keys())))
 
-            if not task.options.nocache and cache_name in self.cache:
+            cache_value = self.cache.get(cache_name, None)
+
+            if not task.options.nocache and cache_value:
                 # return from the cache
                 log.trace('cache hit')
                 entries = []
-                for entry in self.cache[cache_name]:
+                for entry in cache_value:
                     fresh = copy.deepcopy(entry)
                     entries.append(fresh)
                 if entries:


Test patch: