Skip to content

Commit 20a3934

Browse files
committed
Add cache view to example app
1 parent 6ef77a1 commit 20a3934

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

example/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
# Cache and database
7575

76-
CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
76+
CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
7777

7878
DATABASES = {
7979
"default": {

example/templates/cache.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
5+
<title>Cache</title>
6+
</head>
7+
<body>
8+
<h1>Cache Test</h1>
9+
<p>Check the cache panel to see the cache hits and misses.</p>
10+
</body>
11+
</html>

example/templates/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ <h1>Index of Tests</h1>
1515
<li><a href="/prototype/">Prototype 1.7.3.0</a></li>
1616
<li><a href="{% url 'turbo' %}">Hotwire Turbo</a></li>
1717
<li><a href="{% url 'htmx' %}">htmx</a></li>
18+
<li><a href="{% url 'cache' %}">Cache</a></li>
1819
<li><a href="{% url 'bad_form' %}">Bad form</a></li>
1920
</ul>
2021
<p><a href="/admin/">Django Admin</a></p>

example/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
async_home,
1010
increment,
1111
jinja2_view,
12+
cache_view,
1213
)
1314

1415
urlpatterns = [
@@ -47,6 +48,7 @@
4748
),
4849
name="turbo2",
4950
),
51+
path("cache/", cache_view, name="cache"),
5052
path("admin/", admin.site.urls),
5153
path("ajax/increment", increment, name="ajax_increment"),
5254
] + debug_toolbar_urls()

example/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22

33
from asgiref.sync import sync_to_async
4+
from django.core.cache import cache
45
from django.contrib.auth.models import User
56
from django.http import JsonResponse
67
from django.shortcuts import render
@@ -40,3 +41,10 @@ async def async_db_concurrent(request):
4041
return await sync_to_async(render)(
4142
request, "async_db.html", {"user_count": user_count}
4243
)
44+
45+
46+
def cache_view(request):
47+
cache.set("foo", "bar")
48+
cache.get("foo")
49+
cache.get("baz")
50+
return render(request, "cache.html")

0 commit comments

Comments
 (0)