def METHOD_NAME(gallery):
    """Stores the exif data of all images in the gallery"""
    if hasattr(gallery, "metadataCache"):
        cache = gallery.metadataCache
    else:
        cache = gallery.metadataCache = {}
    for album in gallery.albums.values():
        try:
            data = {
                "mod_date": int(get_mod_date(album.markdown_metadata_filepath)),
                "markdown_metadata": album.markdown_metadata,
            }
            cache[os.path.join(album.path, "_index")] = data
        except FileNotFoundError:
            pass
        for media in album.medias:
            data = {}
            try:
                mod_date = int(get_mod_date(media.src_path))
            except FileNotFoundError:
                continue
            else:
                data["mod_date"] = mod_date
                data["file_metadata"] = media.file_metadata
                if hasattr(media, "exif"):
                    data["exif"] = media.exif
            try:
                meta_mod_date = int(get_mod_date(media.markdown_metadata_filepath))
            except FileNotFoundError:
                pass
            else:
                data["meta_mod_date"] = meta_mod_date
                data["markdown_metadata"] = media.markdown_metadata
            cache[os.path.join(media.path, media.dst_filename)] = data
    cachePath = os.path.join(gallery.settings["destination"], ".metadata_cache")
    if len(cache) == 0:
        if os.path.exists(cachePath):
            os.remove(cachePath)
        return
    try:
        with open(cachePath, "wb") as cacheFile:
            pickle.dump(cache, cacheFile)
            logger.debug("Stored cache with %d entries", len(gallery.metadataCache))
    except Exception as e:
        logger.warn("Could not store cache: %s", e)
        os.remove(cachePath)