mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Adapt to new MemberCacheFlusher interface
This commit is contained in:
parent
45999e1133
commit
2be902ef2f
@ -9,7 +9,7 @@ use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\Hierarchy\Hierarchy;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use SilverStripe\Core\Cache\CacheFlusher;
|
||||
use SilverStripe\Core\Cache\MemberCacheFlusher;
|
||||
/**
|
||||
* Calculates batch permissions for nested objects for:
|
||||
* - canView: Supports 'Anyone' type
|
||||
@ -17,7 +17,7 @@ use SilverStripe\Core\Cache\CacheFlusher;
|
||||
* - canDelete: Includes special logic for ensuring parent objects can only be deleted if their children can
|
||||
* be deleted also.
|
||||
*/
|
||||
class InheritedPermissions implements PermissionChecker, CacheFlusher
|
||||
class InheritedPermissions implements PermissionChecker, MemberCacheFlusher
|
||||
{
|
||||
use Injectable;
|
||||
|
||||
@ -127,20 +127,20 @@ class InheritedPermissions implements PermissionChecker, CacheFlusher
|
||||
* Clear the cache for this instance only
|
||||
* @param array $ids A list of member IDs
|
||||
*/
|
||||
public function flushCache($ids = null)
|
||||
public function flushMemberCache($memberIDs = null)
|
||||
{
|
||||
if (!$this->cacheService) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hard flush, e.g. flush=1
|
||||
if (!$ids) {
|
||||
if (!$memberIDs) {
|
||||
$this->cacheService->clear();
|
||||
}
|
||||
|
||||
if ($ids && is_array($ids)) {
|
||||
if ($memberIDs && is_array($memberIDs)) {
|
||||
foreach ([self::VIEW, self::EDIT, self::DELETE] as $type) {
|
||||
foreach ($ids as $memberID) {
|
||||
foreach ($memberIDs as $memberID) {
|
||||
$key = $this->generateCacheKey($type, $memberID);
|
||||
$this->cacheService->delete($key);
|
||||
}
|
||||
|
@ -347,13 +347,13 @@ class InheritedPermissionsTest extends SapphireTest
|
||||
$permissionChecker = new InheritedPermissions(TestPermissionNode::class, $cache);
|
||||
|
||||
// Non existent ID
|
||||
$permissionChecker->flushCache('dummy');
|
||||
$permissionChecker->flushMemberCache('dummy');
|
||||
foreach([$editKey1, $editKey2, $viewKey1, $viewKey2] as $key) {
|
||||
$this->assertNotNull($cache->get($key));
|
||||
}
|
||||
|
||||
// Precision strike
|
||||
$permissionChecker->flushCache([$member1->ID]);
|
||||
$permissionChecker->flushMemberCache([$member1->ID]);
|
||||
// Member1 should be clear
|
||||
$this->assertNull($cache->get($editKey1));
|
||||
$this->assertNull($cache->get($viewKey1));
|
||||
@ -362,7 +362,7 @@ class InheritedPermissionsTest extends SapphireTest
|
||||
$this->assertNotNull($cache->get($viewKey2));
|
||||
|
||||
// Nuclear
|
||||
$permissionChecker->flushCache();
|
||||
$permissionChecker->flushMemberCache();
|
||||
foreach([$editKey1, $editKey2, $viewKey1, $viewKey2] as $key) {
|
||||
$this->assertNull($cache->get($key));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user