mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Refactor to MemberCacheFlusher
This commit is contained in:
parent
4857816c9e
commit
86458941be
@ -6,11 +6,11 @@ namespace SilverStripe\Core\Cache;
|
|||||||
* Defines a service that can flush its cache for a list of members
|
* Defines a service that can flush its cache for a list of members
|
||||||
* @package SilverStripe\Core\Cache
|
* @package SilverStripe\Core\Cache
|
||||||
*/
|
*/
|
||||||
interface CacheFlusher
|
interface MemberCacheFlusher
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param null $ids
|
* @param null $memberIDs
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function flushCache($ids = null);
|
public function flushMemberCache($memberIDs = null);
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ use Psr\Log\InvalidArgumentException;
|
|||||||
use SilverStripe\Core\Flushable;
|
use SilverStripe\Core\Flushable;
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Core\Cache\CacheFlusher;
|
use SilverStripe\Core\Cache\MemberCacheFlusher;
|
||||||
|
|
||||||
class InheritedPermissionFlusher extends DataExtension implements Flushable
|
class InheritedPermissionFlusher extends DataExtension implements Flushable
|
||||||
{
|
{
|
||||||
@ -48,11 +48,11 @@ class InheritedPermissionFlusher extends DataExtension implements Flushable
|
|||||||
public function setServices($services)
|
public function setServices($services)
|
||||||
{
|
{
|
||||||
foreach ($services as $service) {
|
foreach ($services as $service) {
|
||||||
if (!$service instanceof CacheFlusher) {
|
if (!$service instanceof MemberCacheFlusher) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'%s.services must contain only %s instances. %s provided.',
|
'%s.services must contain only %s instances. %s provided.',
|
||||||
__CLASS__,
|
__CLASS__,
|
||||||
CacheFlusher::class,
|
MemberCacheFlusher::class,
|
||||||
get_class($service)
|
get_class($service)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ class InheritedPermissionFlusher extends DataExtension implements Flushable
|
|||||||
{
|
{
|
||||||
$ids = $this->getMemberIDList();
|
$ids = $this->getMemberIDList();
|
||||||
foreach ($this->services as $service) {
|
foreach ($this->services as $service) {
|
||||||
$service->flushCache($ids);
|
$service->flushMemberCache($ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
namespace SilverStripe\Security\Tests\InheritedPermissionsFlusherTest;
|
namespace SilverStripe\Security\Tests\InheritedPermissionsFlusherTest;
|
||||||
|
|
||||||
use Psr\SimpleCache\CacheInterface;
|
use Psr\SimpleCache\CacheInterface;
|
||||||
use SilverStripe\Core\Cache\CacheFlusher;
|
use SilverStripe\Core\Cache\MemberCacheFlusher;
|
||||||
|
|
||||||
class TestCacheFlusher implements CacheFlusher
|
class TestCacheFlusher implements MemberCacheFlusher
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -32,22 +32,22 @@ class TestCacheFlusher implements CacheFlusher
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the cache for this instance only
|
* Clear the cache for this instance only
|
||||||
* @param array $ids A list of member IDs
|
* @param array $memberIDs A list of member IDs
|
||||||
*/
|
*/
|
||||||
public function flushCache($ids = null)
|
public function flushMemberCache($memberIDs = null)
|
||||||
{
|
{
|
||||||
if (!$this->cache) {
|
if (!$this->cache) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hard flush, e.g. flush=1
|
// Hard flush, e.g. flush=1
|
||||||
if (!$ids) {
|
if (!$memberIDs) {
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ids && is_array($ids)) {
|
if ($memberIDs && is_array($memberIDs)) {
|
||||||
foreach (self::$categories as $category) {
|
foreach (self::$categories as $category) {
|
||||||
foreach ($ids as $memberID) {
|
foreach ($memberIDs as $memberID) {
|
||||||
$key = $this->generateCacheKey($category, $memberID);
|
$key = $this->generateCacheKey($category, $memberID);
|
||||||
$this->cache->delete($key);
|
$this->cache->delete($key);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user