diff --git a/docs/en/04_Changelogs/4.2.0.md b/docs/en/04_Changelogs/4.2.0.md index bd6ebc7db..9fc2c7055 100644 --- a/docs/en/04_Changelogs/4.2.0.md +++ b/docs/en/04_Changelogs/4.2.0.md @@ -171,3 +171,33 @@ $gridField = new GridField('Teams', 'Teams', $this->Teams(), $config); // method 2: removing GridField_ActionMenu from an existing GridField $gridField->getConfig()->removeComponentsByType(GridField_ActionMenu); ``` +### Versioned cache segmentation + +The cache API now maintains separate cache pools for each versioned stage. This prevents users from caching draft data and then exposing it on the live stage. + +```php +// Before: +$cache = Injector::inst()->get(CacheInterface::class . '.myapp'); +Versioned::set_stage(Versioned::DRAFT); +$cache->set('my_key', 'Some draft content. Not for public viewing yet.'); +Versioned::set_stage(Versioned::LIVE); +$cache->get('my_key'); // 'Some draft content. Not for public viewing yet' + +// After: +$cache = Injector::inst()->get(CacheInterface::class . '.myapp'); +Versioned::set_stage(Versioned::DRAFT); +$cache->set('my_key', 'Some draft content. Not for public viewing yet.'); +Versioned::set_stage(Versioned::LIVE); +$cache->get('my_key'); // null +``` +Data that is not content sensitive can be cached across stages by simply opting out of the segmented cache with the `disable-container` argument. + +```yaml +SilverStripe\Core\Injector\Injector: + Psr\SimpleCache\CacheInterface.myapp: + factory: SilverStripe\Core\Cache\CacheFactory + constructor: + namespace: "MyInsensitiveData" + args: + disable-container: true +```