Skip to content

Commit

Permalink
Merge branch 'main' into replace-python-jose-by-pyjwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Squidtyper authored Jun 6, 2024
2 parents 3b2fab8 + 84f51c8 commit 5bf59e3
Show file tree
Hide file tree
Showing 26 changed files with 529 additions and 135 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,15 @@
"contributions": [
"doc"
]
},
{
"login": "jderrien",
"name": "jderrien",
"avatar_url": "https://avatars.githubusercontent.com/u/145396?v=4",
"profile": "https://github.com/jderrien",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Download artifact
uses: dawidd6/action-download-artifact@v3
uses: dawidd6/action-download-artifact@v5
with:
workflow_conclusion: success
run_id: ${{ github.event.workflow_run.id }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ see [the contribution guide](CONTRIBUTING.rst).
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="http://0110.be"><img src="https://avatars.githubusercontent.com/u/60453?v=4?s=100" width="100px;" alt="Joren Six"/><br /><sub><b>Joren Six</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/commits?author=JorenSix" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jderrien"><img src="https://avatars.githubusercontent.com/u/145396?v=4?s=100" width="100px;" alt="jderrien"/><br /><sub><b>jderrien</b></sub></a><br /><a href="https://github.com/litestar-org/litestar/commits?author=jderrien" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions docs/examples/caching/cache.py
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],
)
9 changes: 9 additions & 0 deletions docs/examples/caching/key_builder.py
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))
13 changes: 13 additions & 0 deletions docs/examples/caching/key_builder_for_route_handler.py
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])
20 changes: 20 additions & 0 deletions docs/examples/caching/redis_store.py
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,
)
6 changes: 5 additions & 1 deletion docs/examples/plugins/flash_messages/jinja.py
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],
)
6 changes: 5 additions & 1 deletion docs/examples/plugins/flash_messages/mako.py
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],
)
6 changes: 5 additions & 1 deletion docs/examples/plugins/flash_messages/minijinja.py
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],
)
8 changes: 7 additions & 1 deletion docs/examples/plugins/flash_messages/usage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from litestar import Litestar, Request, get
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar.middleware.session.server_side import ServerSideSessionConfig
from litestar.plugins.flash import FlashConfig, FlashPlugin, flash
from litestar.response import Template
from litestar.template.config import TemplateConfig
Expand All @@ -23,4 +24,9 @@ async def index(request: Request) -> Template:
)


app = Litestar(plugins=[flash_plugin], route_handlers=[index], template_config=template_config)
app = Litestar(
plugins=[flash_plugin],
route_handlers=[index],
template_config=template_config,
middleware=[ServerSideSessionConfig().middleware],
)
Loading

0 comments on commit 5bf59e3

Please sign in to comment.