Skip to content

Cache Management

nflreadpy.clear_cache

clear_cache(pattern: str | None = None) -> None

Clear cached data entries matching a pattern.

This is the main function for clearing nflreadpy's cache. It provides a simple interface to the underlying CacheManager functionality.

Parameters:

Name Type Description Default
pattern str | None

Optional string pattern to match against cached data. If None, clears all cached data. Pattern matching is performed on cache keys, which typically contain URLs and parameters.

None

Examples:

>>> import nflreadpy as nfl
>>> nfl.clear_cache()  # Clear all cached data
>>> nfl.clear_cache("pbp_2023")  # Clear 2023 play-by-play data
>>> nfl.clear_cache("roster")  # Clear all roster data
Note

This affects both memory and filesystem cache depending on your cache configuration. See nflreadpy.config for cache settings.

See Also

nflreadr clear_cache reference

Source code in src/nflreadpy/cache.py
def clear_cache(pattern: str | None = None) -> None:
    """Clear cached data entries matching a pattern.

    This is the main function for clearing nflreadpy's cache. It provides a simple
    interface to the underlying CacheManager functionality.

    Args:
        pattern: Optional string pattern to match against cached data.
               If None, clears all cached data. Pattern matching is performed
               on cache keys, which typically contain URLs and parameters.

    Examples:
        >>> import nflreadpy as nfl
        >>> nfl.clear_cache()  # Clear all cached data
        >>> nfl.clear_cache("pbp_2023")  # Clear 2023 play-by-play data
        >>> nfl.clear_cache("roster")  # Clear all roster data

    Note:
        This affects both memory and filesystem cache depending on your
        cache configuration. See nflreadpy.config for cache settings.

    See Also:
        [nflreadr clear_cache reference](https://nflreadr.nflverse.com/reference/clear_cache.html)
    """
    _cache_manager.clear(pattern)