controls
controls
¶
Per-call request controls (cache and rate-limit overrides).
These use :mod:contextvars, so they work identically for sync code and
asyncio tasks, and never leak across concurrent tasks.
Example::
from cocapi import cache_control, without_rate_limit
with cache_control(lookup=False): # force a fresh fetch
clan = api.clan_tag("#ABC")
with cache_control(update=False): # don't store this response
clan = api.clan_tag("#ABC")
with without_rate_limit(): # skip the async rate limiter
data = await api.clan_tag("#ABC")
cache_control
¶
cache_control(
lookup: bool = True, update: bool = True
) -> Iterator[None]
Override response caching for requests made inside the with block.
| PARAMETER | DESCRIPTION |
|---|---|
lookup
|
If False, ignore any cached entry and hit the API.
TYPE:
|
update
|
If False, don't store the fresh response in the cache.
TYPE:
|
Source code in cocapi/controls.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
without_rate_limit
¶
without_rate_limit() -> Iterator[None]
Bypass the async rate limiter for requests made inside the block.
Source code in cocapi/controls.py
47 48 49 50 51 52 53 54 | |