PHPackages                             somardigital/silverstripe-cloudfront - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. somardigital/silverstripe-cloudfront

ActiveSilverstripe-vendormodule[Caching](/categories/caching)

somardigital/silverstripe-cloudfront
====================================

SilverStripe extension to automatically invalidate CloudFront cache when pages and files are published, unpublished, or deleted

v2.0.2(2mo ago)0141BSD-3-Clause

Since Feb 26Compare

[ Source](https://github.com/somardigital/silverstripe-cloudfront)[ Packagist](https://packagist.org/packages/somardigital/silverstripe-cloudfront)[ RSS](/packages/somardigital-silverstripe-cloudfront/feed)WikiDiscussions Synced 3w ago

READMEChangelog (1)Dependencies (7)Versions (5)Used By (0)

Silverstripe CloudFront
=======================

[](#silverstripe-cloudfront)

Invalidate CloudFront cache when pages and files are published, unpublished, or deleted in Silverstripe CMS.

Problem Statement
-----------------

[](#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
--------

[](#solution)

This module provides:

- **`InvalidateCacheExtension`** - Hooks into Silverstripe ORM events to invalidate matching dataobject
- **`ElementalInvalidateCacheExtension`** - On elemental block publish clear page cache
- **`MemberSessionCookieExtension`** - Sets a cookie to bypass standard cached pages
- **`CloudfrontService`** - Handles AWS CloudFront invalidation requests
- **`CloudFrontClientFactory`** - 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
------------

[](#requirements)

- Silverstripe Framework ^6
- Silverstripe CMS ^6
- AWS SDK for PHP ^3.379 (installed automatically via Composer)
- AWS CloudFront distribution with valid credentials

Installation
------------

[](#installation)

### Via Composer (recommended)

[](#via-composer-recommended)

```
composer require "somardigital/silverstripe-cloudfront"
```

Or for local development add this to composer.json:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "../silverstripe-cloudfront"
        }
    ]
}
```

Then run:

```
composer require "somardigital/silverstripe-cloudfront:@dev"
```

### Manual Installation

[](#manual-installation)

1. Clone this repository into your project
2. Run `composer install` in your project root
3. Run `vendor/bin/sake dev/build flush=1`

Usage
-----

[](#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
-------------

[](#configuration)

### AWS Credentials

[](#aws-credentials)

Add the following to your `.env` file:

```
# AWS CloudFront Configuration
AWS_ACCESS_KEY_ID=your_access_key_here
AWS_SECRET_ACCESS_KEY=your_secret_key_here
CLOUDFRONT_DISTRIBUTION_ID=your_distribution_id_here
```

How It Works
------------

[](#how-it-works)

1. The extension hooks into Silverstripe's ORM events:

    - `onAfterPublish`
    - `onAfterUnpublish`
    - `onAfterDelete`
2. When triggered, it retrieves the object's public URL:

    - For `SiteTree`: uses `Link()`
    - For `File`: uses `Link()`
3. 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.
4. If invalidation fails, it logs a warning but doesn't break the publish/delete process

### CMS User Cache Bypass (Optional)

[](#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](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Cookies.html) for details on cookie-based cache behaviors.

#### Enabling the Feature

[](#enabling-the-feature)

Add to your `.env` file:

```
CLOUDFRONT_CACHE_BYPASS_ENABLED=true
```

#### Customizing the Configuration

[](#customizing-the-configuration)

You can customize the cookie name and required permission in your project's YAML configuration:

```
Somar\CloudFront\Extensions\MemberSessionCookieExtension:
  cookie_name: 'my-custom-cookie'
  required_permission: 'ADMIN'
```

**Default values:**

- `cookie_name`: `ss-cms-user`
- `required_permission`: `CMS_ACCESS_CMSMain`

#### How It Works

[](#how-it-works-1)

When `CLOUDFRONT_CACHE_BYPASS_ENABLED=true`:

1. **On Login**: If the member has the required permission (default: `CMS_ACCESS_CMSMain`), the configured cookie is set in their browser
2. **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.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance84

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

4

Last Release

82d ago

Major Versions

v1.0.0 → v2.0.02026-05-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/bce9c498c70d4e91777ac18d409d6736beaf243582727dd2d5f1eb368c239401?d=identicon)[somardesignstudios](/maintainers/somardesignstudios)

---

Tags

awssilverstripecachecloudfrontinvalidation

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/somardigital-silverstripe-cloudfront/health.svg)

```
[![Health](https://phpackages.com/badges/somardigital-silverstripe-cloudfront/health.svg)](https://phpackages.com/packages/somardigital-silverstripe-cloudfront)
```

###  Alternatives

[silverstripe/userforms

UserForms enables CMS users to create dynamic forms via a drag and drop interface and without getting involved in any PHP code

1321.1M86](/packages/silverstripe-userforms)[silverstripe/staticpublishqueue

Static publishing queue to create static versions of pages for enhanced performance and security

44140.1k6](/packages/silverstripe-staticpublishqueue)[symbiote/silverstripe-advancedworkflow

Adds configurable workflow support to the CMS, with a GUI for creating custom workflow definitions.

46302.4k9](/packages/symbiote-silverstripe-advancedworkflow)[steadlane/silverstripe-cloudflare

This module aims to relieve the stress of using Cloudflare caching with any SilverStripe project. Adds extension hooks that clears Cloudflare's cache for a specific page when that page is published or unpublished.

233.7k](/packages/steadlane-silverstripe-cloudflare)[silverstripe-terraformers/keys-for-cache

Silverstripe cache key management

1530.0k](/packages/silverstripe-terraformers-keys-for-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
