def get_materialized_data_cache(doc=None):
    """Return the cache directory where data can be written during a build, usually for
    a Jupyter notebook that generates many files for each execution"""

    from metapack.constants import MATERIALIZED_DATA_PREFIX
    from os.path import join

    if not doc:
        from metapack import Downloader
        downloader = Downloader()
        return downloader.cache.getsyspath(MATERIALIZED_DATA_PREFIX)
    else:
        dr = doc._cache.getsyspath(join(MATERIALIZED_DATA_PREFIX, doc.name))

        ensure_dir(dr)

        return dr