-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into replace-python-jose-by-pyjwt
- Loading branch information
Showing
26 changed files
with
529 additions
and
135 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
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, | ||
) |
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,9 +1,13 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.jinja import JinjaTemplateEngine | ||
from litestar.middleware.session.server_side import ServerSideSessionConfig | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=JinjaTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
app = Litestar(plugins=[flash_plugin]) | ||
app = Litestar( | ||
plugins=[flash_plugin], | ||
middleware=[ServerSideSessionConfig().middleware], | ||
) |
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,9 +1,13 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.mako import MakoTemplateEngine | ||
from litestar.middleware.session.server_side import ServerSideSessionConfig | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=MakoTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
app = Litestar(plugins=[flash_plugin]) | ||
app = Litestar( | ||
plugins=[flash_plugin], | ||
middleware=[ServerSideSessionConfig().middleware], | ||
) |
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,9 +1,13 @@ | ||
from litestar import Litestar | ||
from litestar.contrib.minijinja import MiniJinjaTemplateEngine | ||
from litestar.middleware.session.server_side import ServerSideSessionConfig | ||
from litestar.plugins.flash import FlashConfig, FlashPlugin | ||
from litestar.template.config import TemplateConfig | ||
|
||
template_config = TemplateConfig(engine=MiniJinjaTemplateEngine, directory="templates") | ||
flash_plugin = FlashPlugin(config=FlashConfig(template_config=template_config)) | ||
|
||
app = Litestar(plugins=[flash_plugin]) | ||
app = Litestar( | ||
plugins=[flash_plugin], | ||
middleware=[ServerSideSessionConfig().middleware], | ||
) |
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
Oops, something went wrong.