Skip to content

CacheManager

pokelance.cache.cache_manager ⚓︎

Base ⚓︎

Base class for all caches.

Attributes:

Name Type Description
max_size int

The maximum cache size.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

BaseCache(max_size=100) ⚓︎

Bases: MutableMapping[_KT, _VT]

Base class for all caches.

Parameters:

Name Type Description Default
max_size int

The maximum size of the cache.

100

Attributes:

Name Type Description
_max_size int

The maximum size of the cache.

_cache Dict[_KT, _VT]

The cache itself.

_endpoints Dict[str, CacheEndpoint]

The endpoints that are cached.

_endpoints_by_id Dict[str, str]

Reverse lookup of id (as a string) to CacheEndpoint, for alias resolution.

_identifiers Set[str]

The union of every valid name and id (as strings) for this category.

_endpoints_cached bool

Whether or not the endpoints are cached.

_client PokeLance

The client that this cache is for.

Examples:

Python Console Session
>>> import asyncio
>>> from pokelance import PokeLance
>>>
>>> async def main():
...     client = PokeLance()
...     print(await client.ping())
...     await asyncio.sleep(5)  # Wait for all the endpoints to load automatically. If not just load them manually.
...     # from pokelance.http import Endpoint
...     # data = await client.http.request(Endpoint.get_berry_endpoints())
...     # client.berry._cache.load_documents(str(client.berry.__class__.__name__).lower(), "berry", data)
...     # print(client.berry.cache.berry.endpoints)
...     # await client.berry.cache.berry.load_all(client.http)
...     print(client.berry.cache.berry)
...     await client.berry.cache.berry.save('temp')  # Save the cache to a file.
...     await client.berry.cache.berry.load('temp')  # Load the cache from a file.
...     print(client.berry.cache.berry)
...     await client.close()
>>>
>>> asyncio.run(main())
Source code in pokelance/cache/cache.py
Python
def __init__(self, max_size: int = 100) -> None:
    self._max_size = max_size
    self._cache: t.Dict[_KT, _VT] = {}
    self._endpoints: t.Dict[str, CacheEndpoint] = {}
    self._endpoints_by_id: t.Dict[str, str] = {}
    self._identifiers: t.Set[str] = set()
    self._endpoints_cached: bool = False
    self._endpoints_ready: asyncio.Event = asyncio.Event()

cache property ⚓︎

The cache itself.

Returns:

Type Description
Dict[_KT, _VT]

The cache itself.

endpoints property ⚓︎

The endpoints that are cached.

Returns:

Type Description
Dict[str, CacheEndpoint]

The endpoints that are cached.

identifiers property ⚓︎

Every valid name and id (as strings) for this category.

Built once when the registry loads so all identifiers/aliases can be validated without needing to rebuild the set on every get_*/fetch_* call.

Returns:

Type Description
Set[str]

The set of valid identifiers.

clear() ⚓︎

Clear the cached data only. The endpoint registry is left intact so that a previously-fetched list of names/ids does not need to be re-fetched just to repopulate the data cache.

Source code in pokelance/cache/cache.py
Python
def clear(self) -> None:
    """Clear the cached data only. The endpoint registry is left intact
    so that a previously-fetched list of names/ids does not need to be
    re-fetched just to repopulate the data cache."""
    self._cache.clear()

get(key, default=None) ⚓︎

Get an item from the cache. If the exact key isn't found, it will attempt to resolve an alias (e.g. numeric id vs. name).

Parameters:

Name Type Description Default
key _KT

The key to get.

required
default Union[_VT, _T, None]

The default value to return if the key isn't found.

None
Source code in pokelance/cache/cache.py
Python
def get(self, key: _KT, default: t.Union[_VT, _T, None] = None) -> t.Union[_VT, _T, None]:  # type: ignore
    """Get an item from the cache. If the exact key isn't found, it will attempt to resolve an alias (e.g. numeric id vs. name).

    Parameters
    ----------
    key: _KT
        The key to get.
    default: t.Union[_VT, _T, None]
        The default value to return if the key isn't found.
    """
    if key in self:
        return self[key]
    requested = key.endpoint.split("/")[-1]
    alias = self._endpoints_by_id.get(requested) or self._endpoints.get(requested)
    if alias:
        for k, v in self.items():
            if k.endpoint.split("/")[-1] == str(alias):
                return v
    return default

load(path='.') async ⚓︎

Load the cache from a file.

Parameters:

Name Type Description Default
path str

The path to load the cache from.

'.'
Source code in pokelance/cache/cache.py
Python
async def load(self, path: str = ".") -> None:
    """Load the cache from a file.

    Parameters
    ----------
    path: str
        The path to load the cache from.
    """
    async with aiofiles.open(pathlib.Path(f"{path}/{self.__class__.__name__}.json"), "r") as f:
        data = json.loads(await f.read())

    self._max_size = len(data)
    route_model = importlib.import_module("pokelance.http").__dict__["Route"]
    value_type = str(self.__orig_bases__[0].__args__[1]).split(".")[-1].strip("[]")  # type: ignore

    model = importlib.import_module("pokelance.models").__dict__[value_type]
    if not issubclass(model, BaseModel):
        raise TypeError(f"Expected a subclass of BaseModel, got {type(model)}")

    for endpoint, info in data.items():
        route = route_model(endpoint=endpoint)
        self.setdefault(
            route, [model.from_payload(i) for i in info] if isinstance(info, list) else model.from_payload(info)
        )

load_all() async ⚓︎

Load all documents/data from api into the cache. (Endpoints must be cached first)

Source code in pokelance/cache/cache.py
Python
async def load_all(self) -> None:
    """
    Load all documents/data from api into the cache. (Endpoints must be cached first)
    """
    if not self._endpoints_cached:
        raise RuntimeError("The endpoints have not been cached yet.")
    self._client.logger.info(f"Loading {self.__class__.__name__}...")
    route_model = importlib.import_module("pokelance.http").__dict__["Route"]
    value_type = str(self.__orig_bases__[0].__args__[1]).split(".")[-1].strip("[]")  # type: ignore
    model: "models.BaseModel" = importlib.import_module("pokelance.models").__dict__[value_type]
    self._max_size = len(self._endpoints)
    for endpoint in self._endpoints.values():
        route = route_model.from_raw_url(endpoint.url)
        data = self.get(route, None)
        self.setdefault(route, data if data else model.from_payload(await self._client.http.request(route)))
    self._client.logger.info(f"Loaded {self.__class__.__name__}.")

load_all_batch(batch_size=20) async ⚓︎

Load all documents/data from api into the cache in parallel. (Endpoints must be cached first)

Parameters:

Name Type Description Default
batch_size int

The number of documents to load at once. Default is 20 to avoid overwhelming the API.

20
Source code in pokelance/cache/cache.py
Python
async def load_all_batch(self, batch_size: int = 20) -> None:
    """
    Load all documents/data from api into the cache in parallel. (Endpoints must be cached first)

    Parameters
    ----------
    batch_size: int
        The number of documents to load at once. Default is 20 to avoid overwhelming the API.
    """
    if not self._endpoints_cached:
        raise RuntimeError("The endpoints have not been cached yet.")

    self._client.logger.info(f"Loading {self.__class__.__name__}...")
    route_model = importlib.import_module("pokelance.http").__dict__["Route"]
    value_type = str(self.__orig_bases__[0].__args__[1]).split(".")[-1].strip("[]")  # type: ignore

    model = importlib.import_module("pokelance.models").__dict__[value_type]
    if not issubclass(model, BaseModel):
        raise TypeError(f"Expected a subclass of BaseModel, got {type(model)}")

    self._max_size = len(self._endpoints)
    endpoints = list(self._endpoints.values())
    total_endpoints = len(endpoints)
    for i in range(0, total_endpoints, batch_size):
        batch = endpoints[i : i + batch_size]
        tasks = []
        for endpoint in batch:
            route = route_model.from_raw_url(endpoint.url)
            data = self.get(route, None)
            if data:
                self.setdefault(route, data)
                self._client.logger.info(f"Cached {route} - existing data used.")
            else:
                tasks.append(self._fetch_and_cache(route, model))
        if tasks:
            await asyncio.gather(*tasks)
        self._client.logger.debug(
            f"Loaded batch {i//batch_size + 1}/{(total_endpoints + batch_size - 1)//batch_size} for {self.__class__.__name__}"
        )
    self._client.logger.info(f"Loaded {self.__class__.__name__} - {len(self._cache)}/{total_endpoints} items.")

load_documents(data) ⚓︎

Load documents into the cache.

Parameters:

Name Type Description Default
data List[Dict[str, str]]

The data to load.

required
Source code in pokelance/cache/cache.py
Python
def load_documents(self, data: t.List[t.Dict[str, str]]) -> None:
    """Load documents into the cache.

    Parameters
    ----------
    data: t.List[t.Dict[str, str]]
        The data to load.
    """
    self.reset_endpoints()
    for document in data:
        id_ = int(document["url"].split("/")[-2])
        self._endpoints[document["name"]] = CacheEndpoint(url=document["url"], id=id_)
        self._endpoints_by_id[str(id_)] = document["name"]
    self._mark_endpoints_cached()

reset_endpoints() ⚓︎

Clear the endpoint registry and re-arm the per-cache ready event.

After this call, wait_until_ready() on this cache will block again until _mark_endpoints_cached() is invoked by the new load.

Source code in pokelance/cache/cache.py
Python
def reset_endpoints(self) -> None:
    """Clear the endpoint registry and re-arm the per-cache ready event.

    After this call, ``wait_until_ready()`` on this cache will block
    again until ``_mark_endpoints_cached()`` is invoked by the new load.
    """
    self._endpoints.clear()
    self._endpoints_by_id.clear()
    self._identifiers.clear()
    self._endpoints_cached = False
    self._endpoints_ready.clear()

save(path='.') async ⚓︎

Save the cache to a file.

Parameters:

Name Type Description Default
path str

The path to save the cache to.

'.'
Source code in pokelance/cache/cache.py
Python
async def save(self, path: str = ".") -> None:
    """Save the cache to a file.

    Parameters
    ----------
    path: str
        The path to save the cache to.
    """
    pathlib.Path(path).mkdir(parents=True, exist_ok=True)
    dummy: t.Dict[str, t.Union[t.Dict[str, t.Any], t.List[t.Dict[str, t.Any]]]] = {
        k.endpoint: ([i.raw for i in v] if isinstance(v, list) else v.raw) for k, v in self.items()  # type: ignore
    }
    async with aiofiles.open(pathlib.Path(f"{path}/{self.__class__.__name__}.json"), "w") as f:
        await f.write("{\n")
        for n, (k, v) in enumerate(dummy.items()):
            await f.write("\n".join([4 * " " + i for i in f'"{k}": {json.dumps(v, indent=4)}'.split("\n")]))
            if n != len(dummy) - 1:
                await f.write(",\n")
        await f.write("\n}")

set_size(size) ⚓︎

Set the size of the cache.

Parameters:

Name Type Description Default
size int

The size of the cache.

required
Source code in pokelance/cache/cache.py
Python
def set_size(self, size: int) -> None:
    """Set the size of the cache.

    Parameters
    ----------
    size: int
        The size of the cache.
    """
    self._max_size = size

wait_until_ready() async ⚓︎

Wait until the all the endpoints are cached.

Source code in pokelance/cache/cache.py
Python
async def wait_until_ready(self) -> None:
    """Wait until the all the endpoints are cached."""
    await self._client.http.connect()
    if self._client.cache_endpoints:
        await self._endpoints_ready.wait()

Berry ⚓︎

Bases: Base

Cache for berry related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

berry BerryCache

The berry.

berry_firmness BerryFirmnessCache

The berry firmness.

berry_flavor BerryFlavorCache

The berry flavor.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Cache ⚓︎

Cache for all endpoints.

Attributes:

Name Type Description
client PokeLance

The pokelance client.

max_size int

The maximum cache size.

berry Berry

The berry cache.

contest Contest

The contest cache.

encounter Encounter

The encounter cache.

evolution Evolution

The evolution cache.

game Game

The game cache.

item Item

The item cache.

location Location

The location cache.

machine Machine

The machine cache.

move Move

The move cache.

pokemon Pokemon

The pokemon cache.

utility Utility

The utility cache.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[Base]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, Base) and obj.default is not None:
            obj.default.clear()

load_documents(category, _type, data) ⚓︎

Loads the endpoint data into the cache.

Parameters:

Name Type Description Default
category str

The category of the endpoint.

required
_type str

The type of the endpoint.

required
data List[Dict[str, str]]

The data to load.

required
Source code in pokelance/cache/cache_manager.py
Python
def load_documents(self, category: str, _type: str, data: t.List[t.Dict[str, str]]) -> None:
    """Loads the endpoint data into the cache.

    Parameters
    ----------
    category: str
        The category of the endpoint.
    _type: str
        The type of the endpoint.
    data: t.List[Dict[str, str]]
        The data to load.
    """
    getattr(getattr(self, category.lower()), _type).load_documents(data)

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[Base]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, Base) and obj.default is not None:
            obj.default.reset()

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[Base]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, Base) and obj.default is not None:
            obj.default.set_size(max_size)

Contest ⚓︎

Bases: Base

Cache for contest related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

contest_type ContestTypeCache

The contest type.

contest_effect ContestEffectCache

The contest effect.

super_contest_effect SuperContestEffectCache

The super contest effect.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Encounter ⚓︎

Bases: Base

Cache for encounter related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

encounter_method EncounterMethodCache

The method in which the encounter happens.

encounter_condition EncounterConditionCache

The condition in which the encounter happens.

encounter_condition_value EncounterConditionValueCache

The condition value in which the encounter happens.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Evolution ⚓︎

Bases: Base

Cache for evolution related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

evolution_chain EvolutionChainCache

The evolution chain of a Pokemon.

evolution_trigger EvolutionTriggerCache

The trigger in which the evolution happens.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Game ⚓︎

Bases: Base

Cache for game related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

generation GamesGenerationCache

The generation of a game.

pokedex GamesPokedexCache

The pokedex of a game.

version GamesVersionCache

The version of a game.

version_group GamesVersionGroupCache

The version group of a game.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Item ⚓︎

Bases: Base

Cache for item related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

item ItemCache

The item.

item_attribute ItemAttributeCache

The attribute of an item.

item_category ItemCategoryCache

The category of an item.

item_fling_effect ItemFlingEffectCache

The fling effect of an item.

item_pocket ItemPocketCache

The pocket of an item.

currency CurrencyCache

The currency of an item.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Location ⚓︎

Bases: Base

Cache for location related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

location LocationCache

The location.

location_area LocationAreaCache

The location area.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Machine ⚓︎

Bases: Base

Cache for machine related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

machine MachineCache

The machine that teaches a move.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Move ⚓︎

Bases: Base

Cache for move related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

move MoveCache

The move.

move_ailment MoveAilmentCache

The ailment of a move.

move_battle_style MoveBattleStyleCache

The battle style of a move.

move_category MoveCategoryCache

The category of a move.

move_damage_class MoveDamageClassCache

The damage class of a move.

move_learn_method MoveLearnMethodCache

The learn method of a move.

move_target MoveTargetCache

The target of a move.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Pokemon ⚓︎

Bases: Base

Cache for pokemon related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

ability AbilityCache

The ability.

characteristic CharacteristicCache

The characteristic.

egg_group EggGroupCache

The egg group.

gender GenderCache

The gender cache.

growth_rate GrowthRateCache

The growth rate.

nature NatureCache

The nature.

pokeathlon_stat PokeathlonStatCache

The pokeathlon stat.

pokemon PokemonCache

The pokemon.

pokemon_color PokemonColorCache

The color of a pokemon.

pokemon_form PokemonFormCache

The form of a pokemon.

pokemon_habitat PokemonHabitatCache

The habitat of a pokemon.

pokemon_shape PokemonShapeCache

The shape of a pokemon.

pokemon_species PokemonSpeciesCache

The species of a pokemon.

stat StatCache

The stat.

type TypeCache

The type.

utility UtilityCache

The utility cache.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Utility ⚓︎

Bases: Base

Cache for utility related endpoints.

Attributes:

Name Type Description
max_size int

The maximum cache size.

language LanguageCache

The language.

api_metadata APIMetadataCache

The API metadata.

clear() ⚓︎

Clear all caches.

Source code in pokelance/cache/cache_manager.py
Python
def clear(self) -> None:
    """Clear all caches."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.clear()

reset() ⚓︎

Reset all endpoint registries.

Source code in pokelance/cache/cache_manager.py
Python
def reset(self) -> None:
    """Reset all endpoint registries."""
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default.reset_endpoints()

set_client(client) ⚓︎

Set the client for the cache.

Parameters:

Name Type Description Default
client PokeLance

The client to set.

required
Source code in pokelance/cache/cache_manager.py
Python
def set_client(self, client: "PokeLance") -> None:
    """Set the client for the cache.

    Parameters
    ----------
    client: pokelance.PokeLance
        The client to set.
    """
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._client = client

set_size(max_size=100) ⚓︎

Set the maximum cache size.

Parameters:

Name Type Description Default
max_size int

The maximum cache size.

100
Source code in pokelance/cache/cache_manager.py
Python
def set_size(self, max_size: int = 100) -> None:
    """Set the maximum cache size.

    Parameters
    ----------
    max_size: int
        The maximum cache size.
    """
    self.max_size = max_size
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        if isinstance(obj.default, BaseCache) and obj.default is not None:
            obj.default._max_size = max_size

wait_until_ready() async ⚓︎

Wait for all sub-caches in this extension to be ready.

Source code in pokelance/cache/cache_manager.py
Python
async def wait_until_ready(self) -> None:
    """Wait for all sub-caches in this extension to be ready."""
    tasks: t.List[t.Awaitable[None]] = []
    obj: attrs.Attribute[BaseCache[t.Any, t.Any]]
    for obj in self.__attrs_attrs__:
        sub_cache = getattr(self, obj.name)
        if isinstance(sub_cache, BaseCache):
            tasks.append(sub_cache.wait_until_ready())
    if tasks:
        await asyncio.gather(*tasks)

Comments