mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
update README.md
This commit is contained in:
@@ -74,6 +74,10 @@ async def startup():
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Initialization
|
||||||
|
|
||||||
|
Firstly you must call `FastAPICache.init` on startup event of `fastapi`, there are some global config you can pass in.
|
||||||
|
|
||||||
### Use `cache` decorator
|
### Use `cache` decorator
|
||||||
|
|
||||||
If you want cache `fastapi` response transparently, you can use `cache` as decorator between router decorator and view function and must pass `request` as param of view function.
|
If you want cache `fastapi` response transparently, you can use `cache` as decorator between router decorator and view function and must pass `request` as param of view function.
|
||||||
@@ -95,6 +99,8 @@ async def index(request: Request, response: Response):
|
|||||||
|
|
||||||
### Custom key builder
|
### Custom key builder
|
||||||
|
|
||||||
|
By default use builtin key builder, if you need, you can override this and pass in `cache` or `FastAPICache.init` to take effect globally.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def my_key_builder(
|
def my_key_builder(
|
||||||
func,
|
func,
|
||||||
@@ -116,7 +122,7 @@ async def index(request: Request, response: Response):
|
|||||||
|
|
||||||
### InMemoryBackend
|
### InMemoryBackend
|
||||||
|
|
||||||
`InMemoryBackend` only support in single node instead of distributed environment.
|
`InMemoryBackend` store cache data in memory and use lazy delete, which mean if you don't access it after cached, it will not delete automatically.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user