| 1 |
from litestar import Litestar |
| 2 |
from litestar.config.response_cache import ResponseCacheConfig |
| 3 |
from litestar.types import HTTPScope |
| 4 |
|
| 5 |
|
| 6 |
def custom_cache_response_filter(_: HTTPScope, status_code: int) -> bool: |
| 7 |
# Cache only 2xx responses |
| 8 |
return 200 <= status_code < 300 |
| 9 |
|
| 10 |
|
| 11 |
response_cache_config = ResponseCacheConfig(cache_response_filter=custom_cache_response_filter) |
| 12 |
|
| 13 |
# Create the app with a custom cache response filter |
| 14 |
app = Litestar( |
| 15 |
response_cache_config=response_cache_config, |
| 16 |
) |