kopia lustrzana https://github.com/wagtail/wagtail
Renamed wagtail.contrib.wagtailfrontendcache to
wagtail.contrib.frontend_cache Conflicts: docs/reference/contrib/frontendcache.rst wagtail/api/v2/signal_handlers.py wagtail/contrib/frontend_cache/signal_handlers.pypull/4068/head
rodzic
4deb1dbff0
commit
7f1b60abca
|
@ -20,27 +20,27 @@ This document describes how to configure Wagtail to purge old versions of pages
|
|||
Setting it up
|
||||
-------------
|
||||
|
||||
Firstly, add ``"wagtail.contrib.wagtailfrontendcache"`` to your INSTALLED_APPS:
|
||||
Firstly, add ``"wagtail.contrib.frontend_cache"`` to your INSTALLED_APPS:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
INSTALLED_APPS = [
|
||||
...
|
||||
|
||||
"wagtail.contrib.wagtailfrontendcache"
|
||||
"wagtail.contrib.frontend_cache"
|
||||
]
|
||||
|
||||
.. versionchanged:: 0.8
|
||||
|
||||
Signal handlers are now automatically registered
|
||||
|
||||
The ``wagtailfrontendcache`` module provides a set of signal handlers which will automatically purge the cache whenever a page is published or deleted. These signal handlers are automatically registered when the ``wagtail.contrib.wagtailfrontendcache`` app is loaded.
|
||||
The ``wagtailfrontendcache`` module provides a set of signal handlers which will automatically purge the cache whenever a page is published or deleted. These signal handlers are automatically registered when the ``wagtail.contrib.frontend_cache`` app is loaded.
|
||||
|
||||
|
||||
Varnish/Squid
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
Add a new item into the ``WAGTAILFRONTENDCACHE`` setting and set the ``BACKEND`` parameter to ``wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend``. This backend requires an extra parameter ``LOCATION`` which points to where the cache is running (this must be a direct connection to the server and cannot go through another proxy).
|
||||
Add a new item into the ``WAGTAILFRONTENDCACHE`` setting and set the ``BACKEND`` parameter to ``wagtail.contrib.frontend_cache.backends.HTTPBackend``. This backend requires an extra parameter ``LOCATION`` which points to where the cache is running (this must be a direct connection to the server and cannot go through another proxy).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -48,7 +48,7 @@ Add a new item into the ``WAGTAILFRONTENDCACHE`` setting and set the ``BACKEND``
|
|||
|
||||
WAGTAILFRONTENDCACHE = {
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000',
|
||||
},
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ Cloudflare
|
|||
|
||||
Firstly, you need to register an account with Cloudflare if you haven't already got one. You can do this here: `Cloudflare Sign up <https://www.cloudflare.com/sign-up>`_
|
||||
|
||||
Add an item into the ``WAGTAILFRONTENDCACHE`` and set the ``BACKEND`` parameter to ``wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend``. This backend requires three extra parameters, ``EMAIL`` (your Cloudflare account email), ``TOKEN`` (your API token from Cloudflare), and ``ZONEID`` (for zone id for your domain, see below).
|
||||
Add an item into the ``WAGTAILFRONTENDCACHE`` and set the ``BACKEND`` parameter to ``wagtail.contrib.frontend_cache.backends.CloudflareBackend``. This backend requires three extra parameters, ``EMAIL`` (your Cloudflare account email), ``TOKEN`` (your API token from Cloudflare), and ``ZONEID`` (for zone id for your domain, see below).
|
||||
|
||||
To find the ``ZONEID`` for your domain, read the `Cloudflare API Documentation <https://api.cloudflare.com/#getting-started-resource-ids>`_
|
||||
|
||||
|
@ -78,7 +78,7 @@ To find the ``ZONEID`` for your domain, read the `Cloudflare API Documentation <
|
|||
|
||||
WAGTAILFRONTENDCACHE = {
|
||||
'cloudflare': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudflareBackend',
|
||||
'EMAIL': 'your-cloudflare-email-address@example.com',
|
||||
'TOKEN': 'your cloudflare api token',
|
||||
'ZONEID': 'your cloudflare domain zone id',
|
||||
|
@ -92,13 +92,13 @@ Amazon CloudFront
|
|||
|
||||
Within Amazon Web Services you will need at least one CloudFront web distribution. If you don't have one, you can get one here: `CloudFront getting started <https://aws.amazon.com/cloudfront/>`_
|
||||
|
||||
Add an item into the ``WAGTAILFRONTENDCACHE`` and set the ``BACKEND`` parameter to ``wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend``. This backend requires one extra parameter, ``DISTRIBUTION_ID`` (your CloudFront generated distribution id).
|
||||
Add an item into the ``WAGTAILFRONTENDCACHE`` and set the ``BACKEND`` parameter to ``wagtail.contrib.frontend_cache.backends.CloudfrontBackend``. This backend requires one extra parameter, ``DISTRIBUTION_ID`` (your CloudFront generated distribution id).
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
WAGTAILFRONTENDCACHE = {
|
||||
'cloudfront': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudfrontBackend',
|
||||
'DISTRIBUTION_ID': 'your-distribution-id',
|
||||
},
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ In case you run multiple sites with Wagtail and each site has its CloudFront dis
|
|||
|
||||
WAGTAILFRONTENDCACHE = {
|
||||
'cloudfront': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudfrontBackend',
|
||||
'DISTRIBUTION_ID': {
|
||||
'www.wagtail.io': 'your-distribution-id',
|
||||
'www.madewithwagtail.org': 'your-distribution-id',
|
||||
|
@ -165,7 +165,7 @@ This signal handler would trigger the invalidation of the index page using the
|
|||
from django.db.models.signals import pre_delete
|
||||
|
||||
from wagtail.core.signals import page_published
|
||||
from wagtail.contrib.wagtailfrontendcache.utils import PurgeBatch
|
||||
from wagtail.contrib.frontend_cache.utils import PurgeBatch
|
||||
|
||||
...
|
||||
|
||||
|
@ -202,7 +202,7 @@ For example, this could be useful for purging a single page on a blog index:
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
from wagtail.contrib.wagtailfrontendcache.utils import PurgeBatch
|
||||
from wagtail.contrib.frontend_cache.utils import PurgeBatch
|
||||
|
||||
# Purge the first page of the blog index
|
||||
batch = PurgeBatch()
|
||||
|
@ -217,7 +217,7 @@ The ``PurgeBatch`` class
|
|||
|
||||
All of the methods available on ``PurgeBatch`` are listed below:
|
||||
|
||||
.. automodule:: wagtail.contrib.wagtailfrontendcache.utils
|
||||
.. automodule:: wagtail.contrib.frontend_cache.utils
|
||||
.. autoclass:: PurgeBatch
|
||||
|
||||
.. automethod:: add_url
|
||||
|
|
|
@ -13,8 +13,8 @@ class WagtailAPIV2AppConfig(AppConfig):
|
|||
def ready(self):
|
||||
# Install cache purging signal handlers
|
||||
if getattr(settings, 'WAGTAILAPI_USE_FRONTENDCACHE', False):
|
||||
if apps.is_installed('wagtail.contrib.wagtailfrontendcache'):
|
||||
if apps.is_installed('wagtail.contrib.frontend_cache'):
|
||||
from wagtail.api.v2.signal_handlers import register_signal_handlers
|
||||
register_signal_handlers()
|
||||
else:
|
||||
raise ImproperlyConfigured("The setting 'WAGTAILAPI_USE_FRONTENDCACHE' is True but 'wagtail.contrib.wagtailfrontendcache' is not in INSTALLED_APPS.")
|
||||
raise ImproperlyConfigured("The setting 'WAGTAILAPI_USE_FRONTENDCACHE' is True but 'wagtail.contrib.frontend_cache' is not in INSTALLED_APPS.")
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals
|
|||
from django.db.models.signals import post_delete, post_save
|
||||
from django.urls import reverse
|
||||
|
||||
from wagtail.contrib.wagtailfrontendcache.utils import purge_url_from_cache
|
||||
from wagtail.contrib.frontend_cache.utils import purge_url_from_cache
|
||||
from wagtail.core.models import get_page_models
|
||||
from wagtail.core.signals import page_published, page_unpublished
|
||||
from wagtail.documents.models import get_document_model
|
||||
|
|
|
@ -490,13 +490,13 @@ class TestDocumentDetail(TestCase):
|
|||
@override_settings(
|
||||
WAGTAILFRONTENDCACHE={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000',
|
||||
},
|
||||
},
|
||||
WAGTAILAPI_BASE_URL='http://api.example.com',
|
||||
)
|
||||
@mock.patch('wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend.purge')
|
||||
@mock.patch('wagtail.contrib.frontend_cache.backends.HTTPBackend.purge')
|
||||
class TestDocumentCacheInvalidation(TestCase):
|
||||
fixtures = ['demosite.json']
|
||||
|
||||
|
|
|
@ -484,13 +484,13 @@ class TestImageDetail(TestCase):
|
|||
@override_settings(
|
||||
WAGTAILFRONTENDCACHE={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000',
|
||||
},
|
||||
},
|
||||
WAGTAILAPI_BASE_URL='http://api.example.com',
|
||||
)
|
||||
@mock.patch('wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend.purge')
|
||||
@mock.patch('wagtail.contrib.frontend_cache.backends.HTTPBackend.purge')
|
||||
class TestImageCacheInvalidation(TestCase):
|
||||
fixtures = ['demosite.json']
|
||||
|
||||
|
|
|
@ -1075,13 +1075,13 @@ class TestPageDetailWithStreamField(TestCase):
|
|||
@override_settings(
|
||||
WAGTAILFRONTENDCACHE={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000',
|
||||
},
|
||||
},
|
||||
WAGTAILAPI_BASE_URL='http://api.example.com',
|
||||
)
|
||||
@mock.patch('wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend.purge')
|
||||
@mock.patch('wagtail.contrib.frontend_cache.backends.HTTPBackend.purge')
|
||||
class TestPageCacheInvalidation(TestCase):
|
||||
fixtures = ['demosite.json']
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
default_app_config = 'wagtail.contrib.frontend_cache.apps.WagtailFrontendCacheAppConfig'
|
|
@ -2,11 +2,11 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
from django.apps import AppConfig
|
||||
|
||||
from wagtail.contrib.wagtailfrontendcache.signal_handlers import register_signal_handlers
|
||||
from wagtail.contrib.frontend_cache.signal_handlers import register_signal_handlers
|
||||
|
||||
|
||||
class WagtailFrontendCacheAppConfig(AppConfig):
|
||||
name = 'wagtail.contrib.wagtailfrontendcache'
|
||||
name = 'wagtail.contrib.frontend_cache'
|
||||
label = 'wagtailfrontendcache'
|
||||
verbose_name = "Wagtail frontend cache"
|
||||
|
|
@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
from django.apps import apps
|
||||
|
||||
from wagtail.contrib.wagtailfrontendcache.utils import purge_page_from_cache
|
||||
from wagtail.contrib.frontend_cache.utils import purge_page_from_cache
|
||||
from wagtail.core.signals import page_published, page_unpublished
|
||||
|
||||
|
|
@ -5,9 +5,9 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from wagtail.contrib.wagtailfrontendcache.backends import (
|
||||
from wagtail.contrib.frontend_cache.backends import (
|
||||
BaseBackend, CloudflareBackend, CloudfrontBackend, HTTPBackend)
|
||||
from wagtail.contrib.wagtailfrontendcache.utils import get_backends
|
||||
from wagtail.contrib.frontend_cache.utils import get_backends
|
||||
from wagtail.tests.testapp.models import EventIndex
|
||||
from wagtail.core.models import Page
|
||||
|
||||
|
@ -25,7 +25,7 @@ class TestBackendConfiguration(TestCase):
|
|||
def test_varnish(self):
|
||||
backends = get_backends(backend_settings={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000',
|
||||
},
|
||||
})
|
||||
|
@ -39,7 +39,7 @@ class TestBackendConfiguration(TestCase):
|
|||
def test_cloudflare(self):
|
||||
backends = get_backends(backend_settings={
|
||||
'cloudflare': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudflareBackend',
|
||||
'EMAIL': 'test@test.com',
|
||||
'TOKEN': 'this is the token',
|
||||
'ZONEID': 'this is a zone id',
|
||||
|
@ -55,7 +55,7 @@ class TestBackendConfiguration(TestCase):
|
|||
def test_cloudfront(self):
|
||||
backends = get_backends(backend_settings={
|
||||
'cloudfront': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudfrontBackend',
|
||||
'DISTRIBUTION_ID': 'frontend',
|
||||
},
|
||||
})
|
||||
|
@ -69,15 +69,15 @@ class TestBackendConfiguration(TestCase):
|
|||
with self.assertRaises(ImproperlyConfigured):
|
||||
get_backends(backend_settings={
|
||||
'cloudfront': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudfrontBackend',
|
||||
},
|
||||
})
|
||||
|
||||
@mock.patch('wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend._create_invalidation')
|
||||
@mock.patch('wagtail.contrib.frontend_cache.backends.CloudfrontBackend._create_invalidation')
|
||||
def test_cloudfront_distribution_id_mapping(self, _create_invalidation):
|
||||
backends = get_backends(backend_settings={
|
||||
'cloudfront': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudfrontBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudfrontBackend',
|
||||
'DISTRIBUTION_ID': {
|
||||
'www.wagtail.io': 'frontend',
|
||||
}
|
||||
|
@ -91,11 +91,11 @@ class TestBackendConfiguration(TestCase):
|
|||
def test_multiple(self):
|
||||
backends = get_backends(backend_settings={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000/',
|
||||
},
|
||||
'cloudflare': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudflareBackend',
|
||||
'EMAIL': 'test@test.com',
|
||||
'TOKEN': 'this is the token',
|
||||
'ZONEID': 'this is a zone id',
|
||||
|
@ -107,11 +107,11 @@ class TestBackendConfiguration(TestCase):
|
|||
def test_filter(self):
|
||||
backends = get_backends(backend_settings={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': 'http://localhost:8000/',
|
||||
},
|
||||
'cloudflare': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.CloudflareBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudflareBackend',
|
||||
'EMAIL': 'test@test.com',
|
||||
'TOKEN': 'this is the token',
|
||||
'ZONEID': 'this is a zone id',
|
||||
|
@ -143,7 +143,7 @@ class MockBackend(BaseBackend):
|
|||
|
||||
@override_settings(WAGTAILFRONTENDCACHE={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.tests.MockBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.tests.MockBackend',
|
||||
},
|
||||
})
|
||||
class TestCachePurgingFunctions(TestCase):
|
||||
|
@ -183,7 +183,7 @@ class TestCachePurgingFunctions(TestCase):
|
|||
|
||||
@override_settings(WAGTAILFRONTENDCACHE={
|
||||
'varnish': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.tests.MockBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.tests.MockBackend',
|
||||
},
|
||||
})
|
||||
class TestCachePurgingSignals(TestCase):
|
|
@ -25,7 +25,7 @@ def get_backends(backend_settings=None, backends=None):
|
|||
if cache_location is not None:
|
||||
backend_settings = {
|
||||
'default': {
|
||||
'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
|
||||
'BACKEND': 'wagtail.contrib.frontend_cache.backends.HTTPBackend',
|
||||
'LOCATION': cache_location,
|
||||
},
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
default_app_config = 'wagtail.contrib.wagtailfrontendcache.apps.WagtailFrontendCacheAppConfig'
|
|
@ -113,7 +113,7 @@ INSTALLED_APPS = (
|
|||
'wagtail.tests.modeladmintest',
|
||||
'wagtail.contrib.wagtailstyleguide',
|
||||
'wagtail.contrib.wagtailroutablepage',
|
||||
'wagtail.contrib.wagtailfrontendcache',
|
||||
'wagtail.contrib.frontend_cache',
|
||||
'wagtail.contrib.wagtailsearchpromotions',
|
||||
'wagtail.contrib.settings',
|
||||
'wagtail.contrib.modeladmin',
|
||||
|
|
Ładowanie…
Reference in New Issue