Download the PHP package somardigital/silverstripe-cloudfront without Composer
On this page you can find all versions of the php package somardigital/silverstripe-cloudfront. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download somardigital/silverstripe-cloudfront
More information about somardigital/silverstripe-cloudfront
Files in somardigital/silverstripe-cloudfront
Package silverstripe-cloudfront
Short Description SilverStripe extension to automatically invalidate CloudFront cache when pages and files are published, unpublished, or deleted
License BSD-3-Clause
Informations about the package silverstripe-cloudfront
Silverstripe CloudFront
Invalidate CloudFront cache when pages and files are published, unpublished, or deleted in Silverstripe CMS.
Problem Statement
When editors publish, unpublish, or delete pages and files, the public-facing site does not update because CloudFront is still serving the old, cached version. This requires manual cache clearing, which is inefficient and error-prone.
Solution
This module provides:
InvalidateCacheExtension- Hooks into Silverstripe ORM events to invalidate matching dataobjectElementalInvalidateCacheExtension- On elemental block publish clear page cacheMemberSessionCookieExtension- Sets a cookie to bypass standard cached pagesCloudfrontService- Handles AWS CloudFront invalidation requestsCloudFrontClientFactory- Creates and configures the AWS CloudFront client
When a page or file is published, unpublished, or deleted, the extension automatically sends invalidation requests to CloudFront. All operations are logged using PSR-3 LoggerInterface for proper observability.
Requirements
- Silverstripe Framework ^6
- Silverstripe CMS ^6
- AWS SDK for PHP ^3.379 (installed automatically via Composer)
- AWS CloudFront distribution with valid credentials
Installation
Via Composer (recommended)
Or for local development add this to composer.json:
Then run:
Manual Installation
- Clone this repository into your project
- Run
composer installin your project root - Run
vendor/bin/sake dev/build flush=1
Usage
The extension is automatically applied to SiteTree and File classes via YAML configuration. No additional setup is required.
When an editor:
- Publishes a page or file → CloudFront cache is invalidated
- Unpublishes a page or file → CloudFront cache is invalidated
- Deletes a page or file → CloudFront cache is invalidated
Configuration
AWS Credentials
Add the following to your .env file:
How It Works
-
The extension hooks into Silverstripe's ORM events:
onAfterPublishonAfterUnpublishonAfterDelete
-
When triggered, it retrieves the object's public URL:
- For
SiteTree: usesLink() - For
File: usesLink()
- For
-
Sends two invalidation paths to CloudFront:
- The exact path:
/about-us - Wildcard path with query params:
/about-us?*
This ensures both the base page and all variations with query parameters are invalidated.
- The exact path:
- If invalidation fails, it logs a warning but doesn't break the publish/delete process
CMS User Cache Bypass (Optional)
This module includes an optional feature to help CMS users bypass CloudFront cache by setting a cookie when they log in. This allows logged-in editors and admins to see the latest content immediately without waiting for cache invalidation.
Note: Setting the cookie alone does not bypass the cache. You must also configure a CloudFront Behavior to bypass caching when this cookie is present. See AWS CloudFront documentation for details on cookie-based cache behaviors.
Enabling the Feature
Add to your .env file:
Customizing the Configuration
You can customize the cookie name and required permission in your project's YAML configuration:
Default values:
cookie_name:ss-cms-userrequired_permission:CMS_ACCESS_CMSMain
How It Works
When CLOUDFRONT_CACHE_BYPASS_ENABLED=true:
- On Login: If the member has the required permission (default:
CMS_ACCESS_CMSMain), the configured cookie is set in their browser - On Logout: The cookie is cleared
This cookie can then be used in CloudFront to create a cache behavior that bypasses the cache for users with this cookie present.
All versions of silverstripe-cloudfront with dependencies
silverstripe/cms Version ^6
aws/aws-sdk-php Version ^3.379