wagtail_cache_block
This project add HTML fragment cache to your StreamField block in easy way
Background
In Wagtail community, it is popular to use the HTML fragment cache at page level.
This works fine in most of the time. But what if some different page have the same block data and some DB query need be run multiple times when rendering?
In this case, it make sense to make HTML fragment cache work on block level instead of page level.
How it works
cache_block is very similar with Django {% cache %} templatetag, it would pull data from block automatically and use the value to generate fragment cache key.
If value in any block field (even descendants of the block) has changed, new fragment key would be generated and new HTML fragment code would be saved to Cache.
cache_block would check if the page is preview mode, if the page if in preview mode, the HTML fragment cache would not be pulled from cache.
I have used it in my projects and the performance has been improved, especially for some page which contains many db query.
Quickstart
Install wagtail_cache_block:
pip install wagtail_cache_block
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'wagtail_cache_block.apps.WagtailCacheBlockConfig',
...
)
You can use it in StreamField for loop iteration
Here 300 is the cache timeout, request is Django RequestContext, and block is the StreamField block.
{% load wagtailcore_tags cache_block_tags %}
{% for block in page.body %}
{% cache_block 300 request block %}
{% include_block block with request=request %}
{% endcache_block %}
{% endfor %}
Or you can use it in block template (For example: StructBlock)
{% load wagtailcore_tags cache_block_tags %}
{% cache_block 300 request block %}
<section class="{{ block.block_type }}">
{{ block.value.heading }}
{{ block.value.paragraph }}
</section>
{% endcache_block %}
History
0.1.0 (2020-01-19)
First release on PyPI.
Metadata
Release files for wagtail-cache-block 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wagtail_cache_block-0.1.3.tar.gz | 6.8 kB | Without provenance | Details for wagtail_cache_block-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wagtail_cache_block-0.1.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for wagtail_cache_block-0.1.3-py2.py3-none-any.whl |
Total release size: 13.2 kB
Release files / wagtail_cache_block-0.1.3.tar.gz
| Download URL | wagtail_cache_block-0.1.3.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1603fa837ddb1234e54f03b5f784f6690985239eef08c5bc40a780d94fb4d807
|
|
BLAKE2b-256 checksum How to use checksums |
2dad4b425c5d6e7afdcefb7cd9f3d6c9af6039280fd1965cb7aef2795f623802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8
|
Release files / wagtail_cache_block-0.1.3-py2.py3-none-any.whl
| Download URL | wagtail_cache_block-0.1.3-py2.py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6c41f082a620f4f57f2cb5fa5d644cc93cfc23d4f7d5d294e8d22b39400ef1c7
|
|
BLAKE2b-256 checksum How to use checksums |
9dd93ba44ca9aeac2c31d9e60cfd745e0b3716fe5f27afbd3526776e31458592
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8
|
Security for wagtail-cache-block 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.