= nblite.config.get_project_root_and_config()[0]
repo_path / '.tmp_cache') set_default_cache_path(repo_path
caching
Utilities for working with notebooks.
set_default_cache_path
set_default_cache_path(cache_path: Path)
Set the path for the temporary cache.
get_default_cache_path
-> Path|None get_default_cache_path()
Set the path for the temporary cache.
show_doc(this_module.get_default_cache)
get_default_cache
get_default_cache()
Retrieve the default cache.
get_default_cache
get_default_cache()
Retrieve the default cache.
get_cache
None]) get_cache(cache_path: Union[Path,
Retrieve a cache instance for the given path. If no path is provided,
the default cache is used. If the cache does not exist, it is created using the specified cache path or the default cache path.
clear_cache_key
None]) clear_cache_key(cache_key, cache: Union[Path,diskcache.Cache,
is_in_cache
tuple, cache: Union[Path,diskcache.Cache,None]) is_in_cache(key:
memoize
memoize(None],
cache: Union[Path,diskcache.Cache,
temp,
typed,
expire,
tag,
return_cache_key )
Decorator for memoizing function results to improve performance.
This decorator stores the results of function calls, allowing subsequent calls with the same arguments to retrieve the result from the cache instead of recomputing it. You can specify a cache object or use a temporary cache if none is provided.
Parameters: - cache (Union[Path, diskcache.Cache, None], optional): A cache object or a path to the cache directory. Defaults to a temporary cache if None. - temp (bool, optional): If True, use a temporary cache. Cannot be True if a cache is provided. Defaults to False. - typed (bool, optional): If True, cache function arguments of different types separately. Defaults to True. - expire (int, optional): Cache expiration time in seconds. If None, cache entries do not expire. - tag (str, optional): A tag to associate with cache entries. - return_cache_key (bool, optional): If True, return the cache key along with the result, in the order (cache_key, result)
. Defaults to False.
Returns: - function: A decorator that applies memoization to the target function.
@memoize(temp=True)
def foo():
1)
time.sleep(return "bar"
# Takes 1 second
foo() # Is retrieved from cache and returns immediately foo()
'bar'
@memoize(return_cache_key=True)
async def async_foo():
1)
time.sleep(return "bar"
await async_foo() # Takes 1 second
= await async_foo() # Is retrieved from cache and returns immediately
cache_key, result # Clears the cache key
clear_cache_key(cache_key) await async_foo(); # This should again take 1 second