mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8093 from open-sausages/pulls/4/versioned-cache-segmentation
Remove versioned cache from core caches
This commit is contained in:
commit
f77969e847
@ -18,11 +18,17 @@ SilverStripe\Core\Injector\Injector:
|
|||||||
factory: SilverStripe\Core\Cache\CacheFactory
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
constructor:
|
constructor:
|
||||||
namespace: "VersionProvider_composerlock"
|
namespace: "VersionProvider_composerlock"
|
||||||
|
args:
|
||||||
|
disable-container: true
|
||||||
Psr\SimpleCache\CacheInterface.RateLimiter:
|
Psr\SimpleCache\CacheInterface.RateLimiter:
|
||||||
factory: SilverStripe\Core\Cache\CacheFactory
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
constructor:
|
constructor:
|
||||||
namespace: 'ratelimiter'
|
namespace: 'ratelimiter'
|
||||||
|
args:
|
||||||
|
disable-container: true
|
||||||
Psr\SimpleCache\CacheInterface.InheritedPermissions:
|
Psr\SimpleCache\CacheInterface.InheritedPermissions:
|
||||||
factory: SilverStripe\Core\Cache\CacheFactory
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
constructor:
|
constructor:
|
||||||
namespace: "InheritedPermissions"
|
namespace: "InheritedPermissions"
|
||||||
|
args:
|
||||||
|
disable-container: true
|
@ -171,3 +171,33 @@ $gridField = new GridField('Teams', 'Teams', $this->Teams(), $config);
|
|||||||
// method 2: removing GridField_ActionMenu from an existing GridField
|
// method 2: removing GridField_ActionMenu from an existing GridField
|
||||||
$gridField->getConfig()->removeComponentsByType(GridField_ActionMenu);
|
$gridField->getConfig()->removeComponentsByType(GridField_ActionMenu);
|
||||||
```
|
```
|
||||||
|
### Versioned cache segmentation
|
||||||
|
|
||||||
|
`SilverStripe\Core\Cache\CacheFactory` 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.
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user