From 272ecfae348a7ff213ee7821c5099b4798e774bb Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Fri, 7 Nov 2025 19:42:29 +1100 Subject: [PATCH 1/2] Add cache view to example app --- example/settings.py | 2 +- example/templates/cache.html | 11 +++++++++++ example/templates/index.html | 1 + example/urls.py | 2 ++ example/views.py | 8 ++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 example/templates/cache.html diff --git a/example/settings.py b/example/settings.py index ffaa09fe5..ad24978ba 100644 --- a/example/settings.py +++ b/example/settings.py @@ -73,7 +73,7 @@ # Cache and database -CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}} +CACHES = {"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}} DATABASES = { "default": { diff --git a/example/templates/cache.html b/example/templates/cache.html new file mode 100644 index 000000000..d95a664bb --- /dev/null +++ b/example/templates/cache.html @@ -0,0 +1,11 @@ + + + + + Cache + + +

Cache Test

+

Check the cache panel to see the cache hits and misses.

+ + diff --git a/example/templates/index.html b/example/templates/index.html index a10c2b5ac..021dc55b7 100644 --- a/example/templates/index.html +++ b/example/templates/index.html @@ -15,6 +15,7 @@

Index of Tests

  • Prototype 1.7.3.0
  • Hotwire Turbo
  • htmx
  • +
  • Cache
  • Bad form
  • Django Admin

    diff --git a/example/urls.py b/example/urls.py index 86e6827fc..b482896b1 100644 --- a/example/urls.py +++ b/example/urls.py @@ -7,6 +7,7 @@ async_db, async_db_concurrent, async_home, + cache_view, increment, jinja2_view, ) @@ -47,6 +48,7 @@ ), name="turbo2", ), + path("cache/", cache_view, name="cache"), path("admin/", admin.site.urls), path("ajax/increment", increment, name="ajax_increment"), ] + debug_toolbar_urls() diff --git a/example/views.py b/example/views.py index 3e1cb04a6..f456f342b 100644 --- a/example/views.py +++ b/example/views.py @@ -1,6 +1,7 @@ import asyncio from asgiref.sync import sync_to_async +from django.core.cache import cache from django.contrib.auth.models import User from django.http import JsonResponse from django.shortcuts import render @@ -40,3 +41,10 @@ async def async_db_concurrent(request): return await sync_to_async(render)( request, "async_db.html", {"user_count": user_count} ) + + +def cache_view(request): + cache.set("foo", "bar") + cache.get("foo") + cache.get("baz") + return render(request, "cache.html") From 357d3d1143bf333983abbacd13fc28dccda7dc8c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 7 Nov 2025 08:46:54 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- example/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/views.py b/example/views.py index f456f342b..b87b02661 100644 --- a/example/views.py +++ b/example/views.py @@ -1,8 +1,8 @@ import asyncio from asgiref.sync import sync_to_async -from django.core.cache import cache from django.contrib.auth.models import User +from django.core.cache import cache from django.http import JsonResponse from django.shortcuts import render