def cleanup(self):
for key in self._find_keys(identity='<STR_LIT:image>'):<EOL><INDENT>image_file = self._get(key)<EOL>if image_file and not image_file.exists():<EOL><INDENT>self.delete(image_file)<EOL><DEDENT><DEDENT>for key in self._find_keys(identity='<STR_LIT>'):<EOL><INDENT>image_file = self._get(key)<EOL>if image_file:<EOL><INDENT>thumbnail_keys = self._get(key, identity='<STR_LIT>') or []<EOL>thumbnail_keys_set = set(thumbnail_keys)<EOL>for thumbnail_key in thumbnail_keys:<EOL><INDENT>if not self._get(thumbnail_key):<EOL><INDENT>thumbnail_keys_set.remove(thumbnail_key)<EOL><DEDENT><DEDENT>thumbnail_keys = list(thumbnail_keys_set)<EOL>if thumbnail_keys:<EOL><INDENT>self._set(key, thumbnail_keys, identity='<STR_LIT>')<EOL>continue<EOL><DEDENT><DEDENT>self._delete(key, identity='<STR_LIT>')<EOL><DEDENT>
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