Skip to content

cache_storage

Cache dataclass

Cache identifier.

Source code in zendriver/cdp/cache_storage.py
@dataclass
class Cache:
    """
    Cache identifier.
    """

    #: An opaque unique id of the cache.
    cache_id: CacheId

    #: Security origin of the cache.
    security_origin: str

    #: Storage key of the cache.
    storage_key: str

    #: The name of the cache.
    cache_name: str

    #: Storage bucket of the cache.
    storage_bucket: typing.Optional[storage.StorageBucket] = None

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["cacheId"] = self.cache_id.to_json()
        json["securityOrigin"] = self.security_origin
        json["storageKey"] = self.storage_key
        json["cacheName"] = self.cache_name
        if self.storage_bucket is not None:
            json["storageBucket"] = self.storage_bucket.to_json()
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> Cache:
        return cls(
            cache_id=CacheId.from_json(json["cacheId"]),
            security_origin=str(json["securityOrigin"]),
            storage_key=str(json["storageKey"]),
            cache_name=str(json["cacheName"]),
            storage_bucket=(
                storage.StorageBucket.from_json(json["storageBucket"])
                if json.get("storageBucket", None) is not None
                else None
            ),
        )

cache_id: CacheId instance-attribute

cache_name: str instance-attribute

security_origin: str instance-attribute

storage_bucket: typing.Optional[storage.StorageBucket] = None class-attribute instance-attribute

storage_key: str instance-attribute

__init__(cache_id, security_origin, storage_key, cache_name, storage_bucket=None)

from_json(json) classmethod

Source code in zendriver/cdp/cache_storage.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Cache:
    return cls(
        cache_id=CacheId.from_json(json["cacheId"]),
        security_origin=str(json["securityOrigin"]),
        storage_key=str(json["storageKey"]),
        cache_name=str(json["cacheName"]),
        storage_bucket=(
            storage.StorageBucket.from_json(json["storageBucket"])
            if json.get("storageBucket", None) is not None
            else None
        ),
    )

to_json()

Source code in zendriver/cdp/cache_storage.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["cacheId"] = self.cache_id.to_json()
    json["securityOrigin"] = self.security_origin
    json["storageKey"] = self.storage_key
    json["cacheName"] = self.cache_name
    if self.storage_bucket is not None:
        json["storageBucket"] = self.storage_bucket.to_json()
    return json

CacheId

Bases: str

Unique identifier of the Cache object.

Source code in zendriver/cdp/cache_storage.py
class CacheId(str):
    """
    Unique identifier of the Cache object.
    """

    def to_json(self) -> str:
        return self

    @classmethod
    def from_json(cls, json: str) -> CacheId:
        return cls(json)

    def __repr__(self):
        return "CacheId({})".format(super().__repr__())

__repr__()

Source code in zendriver/cdp/cache_storage.py
def __repr__(self):
    return "CacheId({})".format(super().__repr__())

from_json(json) classmethod

Source code in zendriver/cdp/cache_storage.py
@classmethod
def from_json(cls, json: str) -> CacheId:
    return cls(json)

to_json()

Source code in zendriver/cdp/cache_storage.py
def to_json(self) -> str:
    return self

CachedResponse dataclass

Cached response

Source code in zendriver/cdp/cache_storage.py
@dataclass
class CachedResponse:
    """
    Cached response
    """

    #: Entry content, base64-encoded. (Encoded as a base64 string when passed over JSON)
    body: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["body"] = self.body
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> CachedResponse:
        return cls(
            body=str(json["body"]),
        )

body: str instance-attribute

__init__(body)

from_json(json) classmethod

Source code in zendriver/cdp/cache_storage.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CachedResponse:
    return cls(
        body=str(json["body"]),
    )

to_json()

Source code in zendriver/cdp/cache_storage.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["body"] = self.body
    return json

CachedResponseType

Bases: Enum

type of HTTP response cached

Source code in zendriver/cdp/cache_storage.py
class CachedResponseType(enum.Enum):
    """
    type of HTTP response cached
    """

    BASIC = "basic"
    CORS = "cors"
    DEFAULT = "default"
    ERROR = "error"
    OPAQUE_RESPONSE = "opaqueResponse"
    OPAQUE_REDIRECT = "opaqueRedirect"

    def to_json(self) -> str:
        return self.value

    @classmethod
    def from_json(cls, json: str) -> CachedResponseType:
        return cls(json)

BASIC = 'basic' class-attribute instance-attribute

CORS = 'cors' class-attribute instance-attribute

DEFAULT = 'default' class-attribute instance-attribute

ERROR = 'error' class-attribute instance-attribute

OPAQUE_REDIRECT = 'opaqueRedirect' class-attribute instance-attribute

OPAQUE_RESPONSE = 'opaqueResponse' class-attribute instance-attribute

from_json(json) classmethod

Source code in zendriver/cdp/cache_storage.py
@classmethod
def from_json(cls, json: str) -> CachedResponseType:
    return cls(json)

to_json()

Source code in zendriver/cdp/cache_storage.py
def to_json(self) -> str:
    return self.value

DataEntry dataclass

Data entry.

Source code in zendriver/cdp/cache_storage.py
@dataclass
class DataEntry:
    """
    Data entry.
    """

    #: Request URL.
    request_url: str

    #: Request method.
    request_method: str

    #: Request headers
    request_headers: typing.List[Header]

    #: Number of seconds since epoch.
    response_time: float

    #: HTTP response status code.
    response_status: int

    #: HTTP response status text.
    response_status_text: str

    #: HTTP response type
    response_type: CachedResponseType

    #: Response headers
    response_headers: typing.List[Header]

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["requestURL"] = self.request_url
        json["requestMethod"] = self.request_method
        json["requestHeaders"] = [i.to_json() for i in self.request_headers]
        json["responseTime"] = self.response_time
        json["responseStatus"] = self.response_status
        json["responseStatusText"] = self.response_status_text
        json["responseType"] = self.response_type.to_json()
        json["responseHeaders"] = [i.to_json() for i in self.response_headers]
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> DataEntry:
        return cls(
            request_url=str(json["requestURL"]),
            request_method=str(json["requestMethod"]),
            request_headers=[Header.from_json(i) for i in json["requestHeaders"]],
            response_time=float(json["responseTime"]),
            response_status=int(json["responseStatus"]),
            response_status_text=str(json["responseStatusText"]),
            response_type=CachedResponseType.from_json(json["responseType"]),
            response_headers=[Header.from_json(i) for i in json["responseHeaders"]],
        )

request_headers: typing.List[Header] instance-attribute

request_method: str instance-attribute

request_url: str instance-attribute

response_headers: typing.List[Header] instance-attribute

response_status: int instance-attribute

response_status_text: str instance-attribute

response_time: float instance-attribute

response_type: CachedResponseType instance-attribute

__init__(request_url, request_method, request_headers, response_time, response_status, response_status_text, response_type, response_headers)

from_json(json) classmethod

Source code in zendriver/cdp/cache_storage.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> DataEntry:
    return cls(
        request_url=str(json["requestURL"]),
        request_method=str(json["requestMethod"]),
        request_headers=[Header.from_json(i) for i in json["requestHeaders"]],
        response_time=float(json["responseTime"]),
        response_status=int(json["responseStatus"]),
        response_status_text=str(json["responseStatusText"]),
        response_type=CachedResponseType.from_json(json["responseType"]),
        response_headers=[Header.from_json(i) for i in json["responseHeaders"]],
    )

to_json()

Source code in zendriver/cdp/cache_storage.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["requestURL"] = self.request_url
    json["requestMethod"] = self.request_method
    json["requestHeaders"] = [i.to_json() for i in self.request_headers]
    json["responseTime"] = self.response_time
    json["responseStatus"] = self.response_status
    json["responseStatusText"] = self.response_status_text
    json["responseType"] = self.response_type.to_json()
    json["responseHeaders"] = [i.to_json() for i in self.response_headers]
    return json

Header dataclass

Source code in zendriver/cdp/cache_storage.py
@dataclass
class Header:
    name: str

    value: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["name"] = self.name
        json["value"] = self.value
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> Header:
        return cls(
            name=str(json["name"]),
            value=str(json["value"]),
        )

name: str instance-attribute

value: str instance-attribute

__init__(name, value)

from_json(json) classmethod

Source code in zendriver/cdp/cache_storage.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Header:
    return cls(
        name=str(json["name"]),
        value=str(json["value"]),
    )

to_json()

Source code in zendriver/cdp/cache_storage.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["name"] = self.name
    json["value"] = self.value
    return json

delete_cache(cache_id)

Deletes a cache.

Parameters:

Name Type Description Default
cache_id CacheId

Id of cache for deletion.

required
Source code in zendriver/cdp/cache_storage.py
def delete_cache(cache_id: CacheId) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Deletes a cache.

    :param cache_id: Id of cache for deletion.
    """
    params: T_JSON_DICT = dict()
    params["cacheId"] = cache_id.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "CacheStorage.deleteCache",
        "params": params,
    }
    json = yield cmd_dict

delete_entry(cache_id, request)

Deletes a cache entry.

Parameters:

Name Type Description Default
cache_id CacheId

Id of cache where the entry will be deleted.

required
request str

URL spec of the request.

required
Source code in zendriver/cdp/cache_storage.py
def delete_entry(
    cache_id: CacheId, request: str
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Deletes a cache entry.

    :param cache_id: Id of cache where the entry will be deleted.
    :param request: URL spec of the request.
    """
    params: T_JSON_DICT = dict()
    params["cacheId"] = cache_id.to_json()
    params["request"] = request
    cmd_dict: T_JSON_DICT = {
        "method": "CacheStorage.deleteEntry",
        "params": params,
    }
    json = yield cmd_dict

request_cache_names(security_origin=None, storage_key=None, storage_bucket=None)

Requests cache names.

Parameters:

Name Type Description Default
security_origin Optional[str]

(Optional) At least and at most one of securityOrigin, storageKey, storageBucket must be specified. Security origin.

None
storage_key Optional[str]

(Optional) Storage key.

None
storage_bucket Optional[StorageBucket]

(Optional) Storage bucket. If not specified, it uses the default bucket.

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, List[Cache]]

Caches for the security origin.

Source code in zendriver/cdp/cache_storage.py
def request_cache_names(
    security_origin: typing.Optional[str] = None,
    storage_key: typing.Optional[str] = None,
    storage_bucket: typing.Optional[storage.StorageBucket] = None,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[Cache]]:
    """
    Requests cache names.

    :param security_origin: *(Optional)* At least and at most one of securityOrigin, storageKey, storageBucket must be specified. Security origin.
    :param storage_key: *(Optional)* Storage key.
    :param storage_bucket: *(Optional)* Storage bucket. If not specified, it uses the default bucket.
    :returns: Caches for the security origin.
    """
    params: T_JSON_DICT = dict()
    if security_origin is not None:
        params["securityOrigin"] = security_origin
    if storage_key is not None:
        params["storageKey"] = storage_key
    if storage_bucket is not None:
        params["storageBucket"] = storage_bucket.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "CacheStorage.requestCacheNames",
        "params": params,
    }
    json = yield cmd_dict
    return [Cache.from_json(i) for i in json["caches"]]

request_cached_response(cache_id, request_url, request_headers)

Fetches cache entry.

Parameters:

Name Type Description Default
cache_id CacheId

Id of cache that contains the entry.

required
request_url str

URL spec of the request.

required
request_headers List[Header]

headers of the request.

required

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, CachedResponse]

Response read from the cache.

Source code in zendriver/cdp/cache_storage.py
def request_cached_response(
    cache_id: CacheId, request_url: str, request_headers: typing.List[Header]
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, 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.
    """
    params: T_JSON_DICT = dict()
    params["cacheId"] = cache_id.to_json()
    params["requestURL"] = request_url
    params["requestHeaders"] = [i.to_json() for i in request_headers]
    cmd_dict: T_JSON_DICT = {
        "method": "CacheStorage.requestCachedResponse",
        "params": params,
    }
    json = yield cmd_dict
    return CachedResponse.from_json(json["response"])

request_entries(cache_id, skip_count=None, page_size=None, path_filter=None)

Requests data from cache.

Parameters:

Name Type Description Default
cache_id CacheId

ID of cache to get entries from.

required
skip_count Optional[int]

(Optional) Number of records to skip.

None
page_size Optional[int]

(Optional) Number of records to fetch.

None
path_filter Optional[str]

(Optional) If present, only return the entries containing this substring in the path

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, Tuple[List[DataEntry], float]]

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.

Source code in zendriver/cdp/cache_storage.py
def request_entries(
    cache_id: CacheId,
    skip_count: typing.Optional[int] = None,
    page_size: typing.Optional[int] = None,
    path_filter: typing.Optional[str] = None,
) -> typing.Generator[
    T_JSON_DICT, T_JSON_DICT, typing.Tuple[typing.List[DataEntry], float]
]:
    """
    Requests data from cache.

    :param cache_id: ID of cache to get entries from.
    :param skip_count: *(Optional)* Number of records to skip.
    :param page_size: *(Optional)* 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.
    """
    params: T_JSON_DICT = dict()
    params["cacheId"] = cache_id.to_json()
    if skip_count is not None:
        params["skipCount"] = skip_count
    if page_size is not None:
        params["pageSize"] = page_size
    if path_filter is not None:
        params["pathFilter"] = path_filter
    cmd_dict: T_JSON_DICT = {
        "method": "CacheStorage.requestEntries",
        "params": params,
    }
    json = yield cmd_dict
    return (
        [DataEntry.from_json(i) for i in json["cacheDataEntries"]],
        float(json["returnCount"]),
    )