-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
146 changed files
with
3,737 additions
and
2,973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ name: "Pull Request Labeler" | |
|
||
on: | ||
pull_request_target: | ||
pull_request: | ||
|
||
jobs: | ||
apply-labels: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from litestar import Litestar, get | ||
from litestar.config.response_cache import CACHE_FOREVER | ||
|
||
|
||
@get("/cached", cache=True) | ||
async def my_cached_handler() -> str: | ||
return "cached" | ||
|
||
|
||
@get("/cached-seconds", cache=120) # seconds | ||
async def my_cached_handler_seconds() -> str: | ||
return "cached for 120 seconds" | ||
|
||
|
||
@get("/cached-forever", cache=CACHE_FOREVER) | ||
async def my_cached_handler_forever() -> str: | ||
return "cached forever" | ||
|
||
|
||
app = Litestar( | ||
[my_cached_handler, my_cached_handler_seconds, my_cached_handler_forever], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from litestar import Litestar, Request | ||
from litestar.config.response_cache import ResponseCacheConfig | ||
|
||
|
||
def key_builder(request: Request) -> str: | ||
return request.url.path + request.headers.get("my-header", "") | ||
|
||
|
||
app = Litestar([], response_cache_config=ResponseCacheConfig(key_builder=key_builder)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from litestar import Litestar, Request, get | ||
|
||
|
||
def key_builder(request: Request) -> str: | ||
return request.url.path + request.headers.get("my-header", "") | ||
|
||
|
||
@get("/cached-path", cache=True, cache_key_builder=key_builder) | ||
async def cached_handler() -> str: | ||
return "cached" | ||
|
||
|
||
app = Litestar([cached_handler]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import asyncio | ||
|
||
from litestar import Litestar, get | ||
from litestar.config.response_cache import ResponseCacheConfig | ||
from litestar.stores.redis import RedisStore | ||
|
||
|
||
@get(cache=10) | ||
async def something() -> str: | ||
await asyncio.sleep(1) | ||
return "something" | ||
|
||
|
||
redis_store = RedisStore.with_client(url="redis://localhost/", port=6379, db=0) | ||
cache_config = ResponseCacheConfig(store="redis_backed_store") | ||
app = Litestar( | ||
[something], | ||
stores={"redis_backed_store": redis_store}, | ||
response_cache_config=cache_config, | ||
) |
13 changes: 7 additions & 6 deletions
13
docs/examples/contrib/prometheus/using_prometheus_exporter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.prometheus import PrometheusConfig, PrometheusController | ||
|
||
# Default app name and prefix is litestar. | ||
prometheus_config = PrometheusConfig() | ||
|
||
def create_app(group_path: bool = False): | ||
# Default app name and prefix is litestar. | ||
prometheus_config = PrometheusConfig(group_path=group_path) | ||
|
||
# By default the metrics are available in prometheus format and the path is set to '/metrics'. | ||
# If you want to change the path and format you can do it by subclassing the PrometheusController class. | ||
# By default the metrics are available in prometheus format and the path is set to '/metrics'. | ||
# If you want to change the path and format you can do it by subclassing the PrometheusController class. | ||
|
||
# Creating the litestar app instance with our custom PrometheusConfig and PrometheusController. | ||
app = Litestar(route_handlers=[PrometheusController], middleware=[prometheus_config.middleware]) | ||
# Creating the litestar app instance with our custom PrometheusConfig and PrometheusController. | ||
return Litestar(route_handlers=[PrometheusController], middleware=[prometheus_config.middleware]) |
Oops, something went wrong.