--
You received this message because you are subscribed to the Google Groups "Wagtail support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+unsubscribe@googlegroups.com.
To post to this group, send email to wag...@googlegroups.com.
Visit this group at https://groups.google.com/group/wagtail.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/8b214ec0-573c-4ca2-93a3-9c511b1bd97b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tobias McNulty
Chief Executive Officer
Hi, Tim!Good question. I wasn't sure about this myself so I did a little digging and here's what I found:
- Django's manual caching facility is used for two things in Wagtail: the sitemap and the root URL for sites, so there is some benefit to setting CACHES. There may be other reasons, I'm not sure.
- As you suggest, using cache_page doesn't really seem possible because there's not a simple way (that I can see) to wrap as_view(), as suggested here. The possible exception to this would be copying wagtailcore.urls into your project and wrapping the "serve" view with cache_page().
- What may also be possible (and I did some basic testing with) is to use the per-site cache, i.e., cache middleware. This won't achieve exactly what you're looking for because there's no invalidation, but for high-traffic sites where you want to avoid the complexity of Varnish or something similar and can afford a small delay in updates (say, 30-60 seconds) this might just do the trick. In local testing this eliminated all but the SQL query to retrieve the Site for me, and the cache middleware should respect many of the same headers that a dedicated frontend cache would.
I'm curious if the per-site cache would work for you. If not, it may be possible for page-level caching to be be added to Wagtail itself, or at least made a little easier for site implementors to add themselves.Let us know what you end up doing!Cheers,Tobias
On Wed, Dec 14, 2016 at 4:04 PM, Tim Allen <fli...@peregrinesalon.com> wrote:
I have looked through the documentation which has plenty of information on Wagtail's front-end cache invalidation, but my team isn't quite to the level of needing Varnish yet.I'm curious how Wagtail works with Django's CACHES setting. I noted that Redis is recommended, but regardless if you're using Redis or memcached or even database caching, I'm wondering how Wagtail interacts with Django's CACHES.Is any Wagtail model class that inherits from Page cached? Are they automagically invalidated when an edit occurs? Is there anything I need to do to get Wagtail to use Django's CACHES, rather than running database queries each time a page is viewed? Since there aren't necessarily user defined Views with Wagtail, I'm a little bit lost without @cache_page.Thanks for any information you can provide.Regards,Tim
--
You received this message because you are subscribed to the Google Groups "Wagtail support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.
To post to this group, send email to wag...@googlegroups.com.
Visit this group at https://groups.google.com/group/wagtail.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/8b214ec0-573c-4ca2-93a3-9c511b1bd97b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
{% load cache %}
{% cache 300 base request.path request.user.username self.pk self.latest_revision_created_at|date:"c" %}
{% block content %}
...
{% endblock %}
{% endcache %}
from datetime import datetime
class BasePage(Page): class Meta: abstract = True
def serve_preview(self, request, mode_name): request.preview_timestamp = datetime.now() return super(BasePage, self).serve_preview(request, mode_name)
class HomePage(BasePage):
... rest of your page code{% cache 300 base request.path request.user.username self.pk self.latest_revision_created_at|date:"c" request.preview_timestamp %}
--
You received this message because you are subscribed to a topic in the Google Groups "Wagtail support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wagtail/SZzBmwf_q0U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wagtail+unsubscribe@googlegroups.com.
To post to this group, send email to wag...@googlegroups.com.
Visit this group at https://groups.google.com/group/wagtail.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/4a25c953-24ed-4853-8221-623353977721%40googlegroups.com.