"""
This type stub file was generated by pyright.
"""

import types
from typing import Any, Callable, Final, Literal, TYPE_CHECKING, TypeVar, Union, overload
from typing_extensions import TypeAlias
from streamlit.runtime.caching.cache_type import CacheType
from streamlit.runtime.caching.cache_utils import Cache, CachedFuncInfo
from streamlit.runtime.caching.cached_message_replay import CachedMessageReplayContext, CachedResult, MsgData
from streamlit.runtime.caching.storage import CacheStorage, CacheStorageContext, CacheStorageManager
from streamlit.runtime.metrics_util import gather_metrics
from streamlit.runtime.stats import CacheStat, CacheStatsProvider
from datetime import timedelta
from streamlit.runtime.caching.hashing import HashFuncsDict

"""@st.cache_data: pickle-based caching."""
if TYPE_CHECKING:
    ...
_LOGGER: Final = ...
CACHE_DATA_MESSAGE_REPLAY_CTX = ...
CachePersistType: TypeAlias = Union[Literal["disk"], None]
class CachedDataFuncInfo(CachedFuncInfo):
    """Implements the CachedFuncInfo interface for @st.cache_data."""
    def __init__(self, func: types.FunctionType, show_spinner: bool | str, persist: CachePersistType, max_entries: int | None, ttl: float | timedelta | str | None, hash_funcs: HashFuncsDict | None = ...) -> None:
        ...
    
    @property
    def cache_type(self) -> CacheType:
        ...
    
    @property
    def cached_message_replay_ctx(self) -> CachedMessageReplayContext:
        ...
    
    @property
    def display_name(self) -> str:
        """A human-readable name for the cached function."""
        ...
    
    def get_function_cache(self, function_key: str) -> Cache:
        ...
    
    def validate_params(self) -> None:
        """
        Validate the params passed to @st.cache_data are compatible with cache storage.

        When called, this method could log warnings if cache params are invalid
        for current storage.
        """
        ...
    


class DataCaches(CacheStatsProvider):
    """Manages all DataCache instances."""
    def __init__(self) -> None:
        ...
    
    def get_cache(self, key: str, persist: CachePersistType, max_entries: int | None, ttl: int | float | timedelta | str | None, display_name: str) -> DataCache:
        """Return the mem cache for the given key.

        If it doesn't exist, create a new one with the given params.
        """
        ...
    
    def clear_all(self) -> None:
        """Clear all in-memory and on-disk caches."""
        ...
    
    def get_stats(self) -> list[CacheStat]:
        ...
    
    def validate_cache_params(self, function_name: str, persist: CachePersistType, max_entries: int | None, ttl: int | float | timedelta | str | None) -> None:
        """Validate that the cache params are valid for given storage.

        Raises
        ------
        InvalidCacheStorageContext
            Raised if the cache storage manager is not able to work with provided
            CacheStorageContext.
        """
        ...
    
    def create_cache_storage_context(self, function_key: str, function_name: str, persist: CachePersistType, ttl_seconds: float | None, max_entries: int | None) -> CacheStorageContext:
        ...
    
    def get_storage_manager(self) -> CacheStorageManager:
        ...
    


_data_caches = ...
def get_data_cache_stats_provider() -> CacheStatsProvider:
    """Return the StatsProvider for all @st.cache_data functions."""
    ...

class CacheDataAPI:
    """Implements the public st.cache_data API: the @st.cache_data decorator, and
    st.cache_data.clear().
    """
    def __init__(self, decorator_metric_name: str) -> None:
        """Create a CacheDataAPI instance.

        Parameters
        ----------
        decorator_metric_name
            The metric name to record for decorator usage.
        """
        ...
    
    F = TypeVar("F", bound=Callable[..., Any])
    @overload
    def __call__(self, func: F) -> F:
        ...
    
    @overload
    def __call__(self, *, ttl: float | timedelta | str | None = ..., max_entries: int | None = ..., show_spinner: bool | str = ..., persist: CachePersistType | bool = ..., experimental_allow_widgets: bool = ..., hash_funcs: HashFuncsDict | None = ...) -> Callable[[F], F]:
        ...
    
    def __call__(self, func: F | None = ..., *, ttl: float | timedelta | str | None = ..., max_entries: int | None = ..., show_spinner: bool | str = ..., persist: CachePersistType | bool = ..., experimental_allow_widgets: bool = ..., hash_funcs: HashFuncsDict | None = ...): # -> Callable[..., Callable[..., Any]] | Callable[..., Any]:
        ...
    
    @gather_metrics("clear_data_caches")
    def clear(self) -> None:
        """Clear all in-memory and on-disk data caches."""
        ...
    


class DataCache(Cache):
    """Manages cached values for a single st.cache_data function."""
    def __init__(self, key: str, storage: CacheStorage, persist: CachePersistType, max_entries: int | None, ttl_seconds: float | None, display_name: str) -> None:
        ...
    
    def get_stats(self) -> list[CacheStat]:
        ...
    
    def read_result(self, key: str) -> CachedResult:
        """Read a value and messages from the cache. Raise `CacheKeyNotFoundError`
        if the value doesn't exist, and `CacheError` if the value exists but can't
        be unpickled.
        """
        ...
    
    @gather_metrics("_cache_data_object")
    def write_result(self, key: str, value: Any, messages: list[MsgData]) -> None:
        """Write a value and associated messages to the cache.
        The value must be pickleable.
        """
        ...
    


