o yf$@sddlZddlZddlZddlZddlZddlZddlmZmZej dej edZ ej dej edZiZeZddZd ed ejfd d Zd dZddZddZdS)N) data_path script_pathZSD_WEBUI_CACHE_FILE cache.jsonZSD_WEBUI_CACHE_DIRcachecCsdS)zEold function for dumping cache to disk; does nothing since diskcache.Nrrr^C:\Users\Luke\Documents\Stable diffusion\Automatic1111\stable-diffusion-webui\modules\cache.py dump_cachesr subsectionreturncCstjtjt|dddS)Nli) size_limitZdisk_min_file_size) diskcacheCacheospathjoin cache_dir)r rrr make_caches  rc Cs&zttddd }t|}Wdn1swYWn#ty(YdStyAtttj t ddt dYdSwt dd| D}tj|d d 5}|D]'\}}t|}|durnt|}|t|<|D] \}}|||<|d qrqYWddS1swYdS) Nrutf8)encodingtmprzb[ERROR] issue occurred while trying to read cache.json; old cache has been moved to tmp/cache.jsoncss|]}t|VqdS)N)len).0 keyvaluesrrr *sz*convert_old_cached_data..zconverting cache)totaldesc)opencache_filenamejsonloadFileNotFoundError Exceptionrreplacerrrprintsumvaluestqdmitemscachesgetrupdate) filedata total_countprogressr r cache_objkeyvaluerrrconvert_old_cached_datas2     "r4cCst|}|s@t/tjtstjtrt t|}|s0t |}|t|<Wd|SWd|S1s;wY|S)z Retrieves or initializes a cache for a specific subsection. Parameters: subsection (str): The subsection identifier for the cache. Returns: diskcache.Cache: The cache data for the specified subsection. N) r*r+ cache_lockrrexistsrisfilerr4r)r r1rrrr8s        c Csxt|}tj|}||}|r|dd}||krd}|r#d|vr8|}|dur,dS||d}|||<t|dS)aP Retrieves or generates data for a specific file, using a caching mechanism. Parameters: subsection (str): The subsection of the cache to use. title (str): The title of the data entry in the subsection of the cache. filename (str): The path to the file to be checked for modifications. func (callable): A function that generates the data if it is not available in the cache. Returns: dict or None: The cached or generated data, or None if data generation fails. The `cached_data_for_file` function implements a caching mechanism for data stored in files. It checks if the data associated with the given `title` is present in the cache and compares the modification time of the file with the cached modification time. If the file has been modified, the cache is considered invalid and the data is regenerated using the provided `func`. Otherwise, the cached data is returned. If the data generation fails, None is returned to indicate the failure. Otherwise, the generated or cached data is returned as a dictionary. mtimerNr3)r8r3)rrrgetmtimer+r) r titlefilenamefuncZexisting_cacheZ ondisk_mtimeentryZ cached_mtimer3rrrcached_data_for_fileQs     r>)r ros.path threadingr r(Z modules.pathsrrenvironr+rrrrr*Lockr5rstrr rr4rr>rrrrs