Skip to content

Commit 177a8ad

Browse files
authored
📝 update config docs
1 parent 7cb51a0 commit 177a8ad

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/usage/configuration.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,51 @@ The `cache_strategy` option defines how to cache the tokens or http responses. Y
7777
Available built-in cache strategies:
7878

7979
- `MemCacheStrategy`: Cache the data in memory.
80+
81+
Normally, you do not need to specifically use this cache strategy. It is used by default.
82+
83+
```python
84+
from githubkit.cache import DEFAULT_CACHE_STRATEGY, MemCacheStrategy
85+
86+
# Use the default cache strategy
87+
github = GitHub(cache_strategy=DEFAULT_CACHE_STRATEGY)
88+
# Or you can initialize another MemCacheStrategy instance
89+
# this will create a new cache instance and not share the cache with the global one
90+
github = GitHub(cache_strategy=MemCacheStrategy())
91+
```
92+
8093
- `RedisCacheStrategy`: Cache the data in Redis (Sync only).
94+
95+
To cache the data in Redis (Sync only), you need to provide a redis client to the `RedisCacheStrategy`. For example:
96+
97+
```python
98+
from redis import Redis
99+
100+
github = GitHub(
101+
cache_strategy=RedisCacheStrategy(
102+
client=Redis(host="localhost", port=6379)
103+
)
104+
)
105+
```
106+
107+
Note that using this sync only cache strategy will cause the `GitHub` instance to be sync only.
108+
81109
- `AsyncRedisCacheStrategy`: Cache the data in Redis (Async only).
82110

111+
To cache the data in Redis (Async only), you need to provide an async redis client to the `AsyncRedisCacheStrategy`. For example:
112+
113+
```python
114+
from redis.asyncio import Redis
115+
116+
github = GitHub(
117+
cache_strategy=AsyncRedisCacheStrategy(
118+
client=Redis(host="localhost", port=6379)
119+
)
120+
)
121+
```
122+
123+
Note that using this async only cache strategy will cause the `GitHub` instance to be async only.
124+
83125
### `http_cache`
84126

85127
The `http_cache` option enables the http caching feature powered by [Hishel](https://hishel.com/) for HTTPX. GitHub API limits the number of requests that you can make within a specific amount of time. This feature is useful to reduce the number of requests to GitHub API and avoid hitting the rate limit.
@@ -92,6 +134,12 @@ Available built-in throttlers:
92134

93135
- `LocalThrottler`: Control the request concurrency in the local process / event loop.
94136

137+
```python
138+
from githubkit.throttling import LocalThrottler
139+
140+
github = GitHub(throttler=LocalThrottler(100))
141+
```
142+
95143
### `auto_retry`
96144

97145
The `auto_retry` option enables request retrying when rate limit exceeded and server error encountered. See [Auto Retry](./auto-retry.md) for more infomation.

0 commit comments

Comments
 (0)