# DO NOT EDIT THIS FILE!
#
# This code is generated off of PyCDP modules. If you need to make
# changes, edit the generator and regenerate all of the modules.

from __future__ import annotations
import typing

from ..context import get_connection_context, get_session_context

import cdp.cache_storage
from cdp.cache_storage import (
    Cache,
    CacheId,
    CachedResponse,
    CachedResponseType,
    DataEntry,
    Header
)


async def delete_cache(
        cache_id: CacheId
    ) -> None:
    '''
    Deletes a cache.

    :param cache_id: Id of cache for deletion.
    '''
    session = get_session_context('cache_storage.delete_cache')
    return await session.execute(cdp.cache_storage.delete_cache(cache_id))


async def delete_entry(
        cache_id: CacheId,
        request: str
    ) -> None:
    '''
    Deletes a cache entry.

    :param cache_id: Id of cache where the entry will be deleted.
    :param request: URL spec of the request.
    '''
    session = get_session_context('cache_storage.delete_entry')
    return await session.execute(cdp.cache_storage.delete_entry(cache_id, request))


async def request_cache_names(
        security_origin: str
    ) -> typing.List[Cache]:
    '''
    Requests cache names.

    :param security_origin: Security origin.
    :returns: Caches for the security origin.
    '''
    session = get_session_context('cache_storage.request_cache_names')
    return await session.execute(cdp.cache_storage.request_cache_names(security_origin))


async def request_cached_response(
        cache_id: CacheId,
        request_url: str,
        request_headers: typing.List[Header]
    ) -> CachedResponse:
    '''
    Fetches cache entry.

    :param cache_id: Id of cache that contains the entry.
    :param request_url: URL spec of the request.
    :param request_headers: headers of the request.
    :returns: Response read from the cache.
    '''
    session = get_session_context('cache_storage.request_cached_response')
    return await session.execute(cdp.cache_storage.request_cached_response(cache_id, request_url, request_headers))


async def request_entries(
        cache_id: CacheId,
        skip_count: int,
        page_size: int,
        path_filter: typing.Optional[str] = None
    ) -> typing.Tuple[typing.List[DataEntry], float]:
    '''
    Requests data from cache.

    :param cache_id: ID of cache to get entries from.
    :param skip_count: Number of records to skip.
    :param page_size: Number of records to fetch.
    :param path_filter: *(Optional)* If present, only return the entries containing this substring in the path
    :returns: A tuple with the following items:

        0. **cacheDataEntries** – Array of object store data entries.
        1. **returnCount** – Count of returned entries from this storage. If pathFilter is empty, it is the count of all entries from this storage.
    '''
    session = get_session_context('cache_storage.request_entries')
    return await session.execute(cdp.cache_storage.request_entries(cache_id, skip_count, page_size, path_filter))
