silverstripe-framework/docs/en/04_Changelogs/3.7.0.md

26 lines
1.3 KiB
Markdown
Raw Normal View History

2018-05-30 06:24:09 +02:00
# 3.7.0
### Versioned cache segmentation
2018-05-30 06:44:47 +02:00
`SS_Cache` now maintains separate cache pools for each versioned stage. This prevents developers from caching draft data and then accidentally exposing it on the live stage without potentially required authorisation checks. Unless you rely on caching across stages, you don't need to change your own code for this change to take effect. Note that cache keys will be internally rewritten, causing any existing cache items to become invalid when this change is deployed.
2018-05-30 06:24:09 +02:00
```php
// Before:
$cache = SS_Cache::factory('myapp');
Versioned::set_reading_mode('Stage.Stage');
2018-05-30 06:44:47 +02:00
$cache->save('Some draft content. Not for public viewing yet.', 'my_key');
Versioned::set_reading_mode('Stage.Live');
2018-05-30 06:24:09 +02:00
$cache->load('my_key'); // 'Some draft content. Not for public viewing yet'
// After:
$cache = SS_Cache::factory('myapp');
Versioned::set_reading_mode('Stage.Stage');
2018-05-30 06:44:47 +02:00
$cache->save('Some draft content. Not for public viewing yet.', 'my_key');
Versioned::set_reading_mode('Stage.Live');
2018-05-30 06:24:09 +02:00
$cache->load('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.
```php
$cache = SS_Cache::factory('myapp', 'Output', array('disable-container' => true));
```