Download the PHP package edwilde/silverstripe-cache-control without Composer

On this page you can find all versions of the php package edwilde/silverstripe-cache-control. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package silverstripe-cache-control

Silverstripe Cache Control

CI

A Silverstripe CMS module that gives content editors control over HTTP Cache-Control headers at both site-wide and page-specific levels.

Features

Version Compatibility

Version Branch CMS Version PHP Version
2.x main CMS 6 PHP 8.3+
1.x cms5 CMS 5 PHP 8.1+

Requirements

Installation

[!NOTE] The nswdpc/silverstripe-cache-headers dependency currently requires its dev-ss6 branch for CMS 6 (no tagged release yet). Your project will need "minimum-stability": "dev" and "prefer-stable": true in its composer.json.

After installation, run:

Usage

Site-wide Settings

Navigate to Settings > Cache Control in the CMS to configure default cache headers:

Vary Header Settings

The Vary Header section in site-wide settings controls which request headers cause separate cache entries to be stored. This tells browsers and CDNs to cache different versions of a page based on these headers:

Vary headers are configured site-wide only — they apply consistently to all pages, including those with page-level cache control overrides.

Page-specific Overrides

Each page has a Cache Control tab where you can:

  1. View the current effective cache control header
  2. Enable override to set page-specific settings
  3. Configure the same options as site-wide settings

The page will show whether settings are inherited from site config or overridden at the page level.

Cache Inheritance (Section-Level Overrides)

For sites with large sections that need different cache settings (e.g., an /archive section with 1000+ pages), you can configure a parent page's cache settings to automatically apply to all its descendant pages.

This feature is disabled by default because it adds database queries per request to walk the page tree. Enable it in your project's YAML config:

Once enabled:

  1. Navigate to the parent page (e.g., /archive) in the CMS
  2. Enable Override Site Cache Settings
  3. Configure the desired cache settings (e.g., 1 day / 86400 seconds)
  4. Check Apply to child pages
  5. Save

All descendant pages that don't have their own cache override will now use the parent's cache settings. The Cache Control tab on each child page will show the inherited source (e.g., "inherited from Archive").

How inheritance resolves:

  1. If a page has its own cache override → uses its own settings
  2. If an ancestor has "Apply to child pages" enabled → uses the nearest ancestor's settings
  3. Otherwise → uses site-wide settings

[!NOTE] This uses runtime tree-walking, not save-time propagation. Changes to a parent's cache settings take effect immediately on the next request to any child page. There is no need to re-save child pages.

[!TIP] For typical Silverstripe sites with 3-5 levels of page depth, the performance overhead is minimal (1-4 additional database queries per uncached request). If your site has deeply nested page trees, consider whether the convenience outweighs the query cost.

Draft Cache Reduction

When a page has been saved but not published, its cache time is automatically reduced to 10 seconds. This ensures that when the page is eventually published, CDN caches expire quickly and visitors see the new content sooner.

This feature is controlled by the "Reduce cache time for pages with unpublished changes" checkbox in Settings > Cache Control > Cache-Control Header (Advanced), and is enabled by default on new installs.

[!IMPORTANT] On an existing site upgrading to this version, the new setting is added to your already-saved configuration in the off state, so the feature starts out disabled. Open Settings > Cache Control, ensure the checkbox is ticked, and save once to enable it. (The default-on value only applies to newly created SiteConfig records via populateDefaults(); it does not retroactively switch on a SiteConfig row that already exists in your database.)

How it works:

  1. Editor saves a page (creates a draft) without publishing
  2. The page's cache max-age is automatically reduced to 10 seconds
  3. When the editor publishes, the normal cache time is restored
  4. If the editor discards draft changes, the normal cache time is also restored

The reduced cache time (default 10 seconds) can be overridden via YAML config:

[!NOTE] The draft detection uses a flag set at save time, not a per-request database query. This means zero performance overhead at request time.

Cache Control Options Explained

Public vs Private

Max Age

Specifies how long (in seconds) the content can be cached before it must be revalidated. The module provides a dropdown with common preset values for ease of use:

Must Revalidate (Recommended)

Forces browsers to check with the server when the cache expires, rather than serving potentially stale content. This is enabled by default and recommended for most scenarios to ensure users receive fresh content when the cache expires.

Cache Duration: No Store

Completely prevents caching. Use for sensitive or rapidly changing content. When "No Store" is selected, all other caching options (max-age, must-revalidate) are ignored and the Cache-Control header will only contain "no-store".

Technical Details

Architecture

The module consists of three main components:

  1. CacheControlSiteConfigExtension: Adds cache control fields to SiteConfig
  2. CacheControlPageExtension: Adds page-level override functionality and optional cache inheritance from parent pages
  3. CacheControlContentControllerExtension: Applies the appropriate cache control headers to responses, resolving from page override → ancestor inheritance → site config

HTTP Headers

The module sets the following HTTP headers:

When max-age is specified, the Expires header is calculated as the current time plus the max-age value in GMT format. This ensures compatibility with older HTTP/1.0 caches and proxies while maintaining full HTTP/1.1 Cache-Control support.

Performance Considerations

Middleware Priority

The middleware runs after request processors to ensure it can detect the current page context. It will not override any Cache-Control headers already set by controllers or other middleware.

Development

Development with Symlinks

If you're developing this module and using a symlink in a Silverstripe project:

  1. The module's vendor/ directory should be excluded from Silverstripe's class manifest
  2. Either remove the vendor directory from the module when symlinking:

  3. Or configure your project to exclude the symlinked vendor directory

This prevents class conflicts when Silverstripe scans for classes.

Running Tests

Test Coverage

The module includes comprehensive PHPUnit tests covering:

Manual Testing of Cache Headers

Cache headers are only applied in test or live environment modes. To verify headers are being set correctly:

Expected output when cache control is enabled with max-age=300:

[!TIP] Headers will not appear in dev mode by default. You have two options:

  1. Switch to test/live mode (recommended for production-like testing):

  2. Enable dev mode bypass (for rapid development/testing):

    When CACHE_HEADERS_IN_DEV is enabled:

    • Cache headers will be applied in dev mode
    • All the same rules for restricted pages apply
    • Pages with forms or restricted access won't be cached
    • This is useful for testing cache behaviour without switching environment modes

License

BSD-3-Clause

Contributing

Contributions are welcome! Please submit pull requests with tests for any fixes or new features.

Thanks :pray:


All versions of silverstripe-cache-control with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
silverstripe/framework Version ^6.0
silverstripe/cms Version ^6.0
unclecheese/display-logic Version ^4.0
nswdpc/silverstripe-cache-headers Version ^2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package edwilde/silverstripe-cache-control contains the following files

Loading the files please wait ...