code: def cleanup(self):
          
          for key in self._find_keys(identity='image'):
              image_file = self._get(key)
  
              if image_file and not image_file.exists():
                  self.delete(image_file)
  
          for key in self._find_keys(identity='thumbnails'):
              # We do not need to check for file existence in here since we
              # already did that above for all image references
              image_file = self._get(key)
  
              if image_file:
                  # if there is an image_file then we check all of its thumbnails
                  # for existence
                  thumbnail_keys = self._get(key, identity='thumbnails') or []
                  thumbnail_keys_set = set(thumbnail_keys)
  
                  for thumbnail_key in thumbnail_keys:
                      if not self._get(thumbnail_key):
                          thumbnail_keys_set.remove(thumbnail_key)
  
                  thumbnail_keys = list(thumbnail_keys_set)
  
                  if thumbnail_keys:
                      self._set(key, thumbnail_keys, identity='thumbnails')
                      continue
  
              # if there is no image_file then this thumbnails key is just
              # hangin' loose, If the thumbnail_keys ended up empty there is no
              # reason for keeping it either
              self._delete(key, identity='thumbnails')
docs: Cleans up the key value store. In detail:
          1. Deletes all key store references for image_files that do not exist
             and all key references for its thumbnails *and* their image_files.
          2. Deletes or updates all invalid thumbnail keys