Cogworks.CogFlare.Core
1.3.12
Prefix Reserved
dotnet add package Cogworks.CogFlare.Core --version 1.3.12
NuGet\Install-Package Cogworks.CogFlare.Core -Version 1.3.12
<PackageReference Include="Cogworks.CogFlare.Core" Version="1.3.12" />
paket add Cogworks.CogFlare.Core --version 1.3.12
#r "nuget: Cogworks.CogFlare.Core, 1.3.12"
// Install Cogworks.CogFlare.Core as a Cake Addin #addin nuget:?package=Cogworks.CogFlare.Core&version=1.3.12 // Install Cogworks.CogFlare.Core as a Cake Tool #tool nuget:?package=Cogworks.CogFlare.Core&version=1.3.12
CogFlare
A package that helps automatically purge CloudFlare cache with Umbraco 12-13
Why is CogFlare Needed?
Most CMS platforms, including Umbraco, are designed to be dynamic and, by default, don’t cache full HTML pages. While they handle caching for assets like JavaScript, CSS, and images, HTML is often left uncached because dynamic pages frequently change. This ensures fresh content but comes with a cost: every request hits the server, even for unchanged pages, leading to unnecessary server load and slower response times.
CogFlare solves this problem by integrating Umbraco with Cloudflare, allowing you to leverage full-page HTML caching through their CDN. While Cloudflare can efficiently cache and serve HTML, the challenge lies in knowing when to purge cached content. Without proper purging, outdated or incorrect content may be served to users.
This is where CogFlare steps in. The package automatically monitors changes in your CMS:
- When nodes or content are updated, CogFlare identifies the affected pages and sends targeted purge requests to Cloudflare.
- Instead of purging the entire site, only the relevant pages are cleared, ensuring efficient caching and fresh content delivery.
By automating the caching and purging process, CogFlare provides the performance benefits of full-page caching without the complexities of managing it manually.
Usage
Basic Functionality
- Automatically purges Cloudflare cache when:
- Content nodes are published, unpublished, or deleted.
- Media items are saved.
- Ability to toggle the package functionality on/off in the settings.
- Ability to toggle logging on/off in the settings.
Advanced Functionality
- Configure Key Nodes in the settings:
- A Key Node is any content node that triggers a FULL site cache purge when it or its referenced nodes are changed (e.g., Site Settings, Navigation, Footers).
- Blocklist blocks that you don’t want to cache by specifying their aliases, with the ability to automatically make form pages uncachable.
Backoffice Dashboard
- A dashboard has been added to the Settings section of the backoffice.
- Currently, only Admins can access it.
- Features include:
- A button to manually trigger a FULL site cache purge.
- Viewing the current configuration for the package.
Logs
Logs are created whenever:
- A node eligible for caching is changed.
- A purge request to Cloudflare is made.
Additional logs display the result of the purge request to Cloudflare:
Installation
Install through dotnet CLI:
dotnet add package Cogworks.CogFlare
Or the NuGet Package Manager:
Install-Package Cogworks.CogFlare
Add these settings to the appsettings.json
"CogFlareSettings": {
"IsEnabled": true,
"ApiKey": "xxx",
"Email": "xxx@xxx.com",
"Endpoint": "https://api.cloudflare.com/client/v4/zones/[zoneId]/purge_cache",
"Domain": "https://www.example.com",
"EnableLogging": true, //optional
"KeyNodes": "1234, 031089", // optional
"BlockAliases": "formBlock, otherFormBlock", // optional
"CacheTime": "2592000" // optional => will default to 1 month
}
To add cache headers to your pages please add the view component in your Master or required page View
@await Component.InvokeAsync(ApplicationConstants.CogFlareCacheHeaders)
Ensure you include the correct using directive at the top of your file:
@using Cogworks.CogFlare.Core.Constants
By default the cache time will be set to 1 month. This can be overriden in the CogFlare Settings
Umbraco Forms and Anti-Forgery Tokens with Full Page HTML Caching
Umbraco Forms include anti-forgery tokens by default. These tokens must be unique for each page to ensure forms function correctly.
However, when implementing full-page HTML caching, this can cause issues: cached pages will reuse the same anti-forgery token, breaking the forms on those pages.
This package provides a solution to ensure both caching and forms can coexist seamlessly.
Problem with Caching and Forms
If you use full-page HTML caching for a page containing an Umbraco form:
- The anti-forgery token will be cached along with the page's HTML.
- When users access the page, the token will no longer be unique, causing form submissions to fail.
Workarounds
To resolve this issue, the package offers two options:
Option 1: Disable Anti-Forgery Tokens
You can disable anti-forgery tokens for the affected pages:
- This allows the page to remain cached while keeping the form functional.
- Caution: Disabling anti-forgery tokens may reduce the security of form submissions.
Option 2: Use Blocklist Aliases to Disable Caching for Specific Pages
This package includes a feature to conditionally disable caching for pages containing specific blocks, such as forms, to avoid the anti-forgery token issue.
How It Works:
- In the
CogFlareSettings
in the appsettings, you can provide a blocklist alias (e.g., a block alias for the Umbraco form or any other block you don’t want to cache). - When rendering the page, the package checks for the presence of any of the specified block aliases.
- If the page includes a block with one of these aliases,
private, no-cache, must-revalidate
will be set for the page, effectively disabling caching for that page.
- In the
Configuration: Add your
BlockAliases
to theCogFlareSettings
:
"CogFlareSettings": {
...
...
"BlockAliases": "formBlock, otherFormBlock"
}
Backoffice User:
Email: admin@admin.com
Password: 0123456789
License
Licensed under the MIT License
© 2024 Cogworks
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Umbraco.Cms.Core (>= 12.0.1)
- Umbraco.Cms.Web.BackOffice (>= 12.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Cogworks.CogFlare.Core:
Package | Downloads |
---|---|
Cogworks.CogFlare
A package that helps automatically purge CloudFlare cache |
GitHub repositories
This package is not used by any popular GitHub repositories.