Commit 0f345005 authored by mrweiner's avatar mrweiner

Rename CacheRegister class and references to Drawer

parent 5fc3e317
......@@ -29,17 +29,17 @@ class CacheRegisterFactory implements CacheRegisterFactoryInterface {
/**
* {@inheritDoc}
*/
public function createRegister(string $implementor_id, $cache_register_id = NULL) {
public function openDrawer(string $implementor_id, $drawer_name = NULL) {
$cache_register_name = $implementor_id;
if ($cache_register_id) {
$bucket_suffix = is_array($cache_register_id)
? implode('.', $cache_register_id)
: $cache_register_id;
if ($drawer_name) {
$bucket_suffix = is_array($drawer_name)
? implode('.', $drawer_name)
: $drawer_name;
$cache_register_name .= ".$bucket_suffix";
}
return new CacheRegister($this->cache, $cache_register_name);
return new Drawer($this->cache, $cache_register_name);
}
}
......@@ -7,20 +7,20 @@ namespace Drupal\cache_register;
interface CacheRegisterFactoryInterface {
/**
* Creates an EasyCache interaction object.
* Creates a Drawer object.
*
* @param string $implementor_id
* This should generally be the implementing module's name.
* It will be used as the beginning of all child slots'
* cache entry IDs.
* @param string|array|null $cache_register_id
* An identifier for the register itself.
* @param string|array|null $drawer_name
* An identifier for the drawer itself.
* It will be appended to the $implementor_id when
* determining child slot's cache entry IDs.
* - If passed an array, slots will be imploded.
*
* @return \Drupal\cache_register\CacheRegisterInterface
* @return \Drupal\cache_register\DrawerInterface
*/
public function createRegister(string $implementor_id, $cache_register_id = NULL);
public function openDrawer(string $implementor_id, $drawer_name = NULL);
}
......@@ -4,7 +4,7 @@ namespace Drupal\cache_register;
use Drupal\Core\Cache\CacheBackendInterface;
class CacheRegister implements CacheRegisterInterface {
class Drawer implements DrawerInterface {
/**
* The cache backend service.
......@@ -14,16 +14,18 @@ class CacheRegister implements CacheRegisterInterface {
protected $cache;
/**
* @var string Used to name the cache.
* This Drawer's identifier.
*
* @var string
*/
protected $registerName;
protected $id;
/**
* Array of slots in the register.
* Array of slots in the drawer.
*
* @var Slot[]
*/
protected $registerSlots = [];
protected $slots = [];
/**
* The constructor.
......@@ -31,15 +33,15 @@ class CacheRegister implements CacheRegisterInterface {
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* Cache backend.
*
* @param string $cache_register_name
* @param string $drawer_id
* Prefixes the cache entry IDs of child Slots.
* This should generally be prefixed by the implementor's name,
* so something like my_module.bookshelf
*/
public function __construct(CacheBackendInterface $cache, string $cache_register_name) {
public function __construct(CacheBackendInterface $cache, string $drawer_id) {
$this->cache = $cache;
// Set to null to help flag if it wasn't implemented in child class
$this->registerName = $cache_register_name;
$this->id = $drawer_id;
}
/**
......@@ -47,29 +49,29 @@ class CacheRegister implements CacheRegisterInterface {
*/
public function createSlot($slot_ids) {
$slot = new Slot($this->cache, $this, $slot_ids);
$this->registerSlots[] = $slot;
$this->slots[] = $slot;
return $slot;
}
/**
* {@inheritDoc}
*/
public function getName() {
return $this->registerName;
public function id() {
return $this->id;
}
/**
* {@inheritDoc}
*/
public function getSlots() {
return $this->registerSlots;
return $this->slots;
}
/**
* {@inheritDoc}
*/
public function deleteAll() {
foreach ($this->registerSlots as $slot) {
foreach ($this->slots as $slot) {
$slot->deleteCache();
}
}
......@@ -78,7 +80,7 @@ class CacheRegister implements CacheRegisterInterface {
* {@inheritDoc}
*/
public function invalidateAll() {
foreach ($this->registerSlots as $slot) {
foreach ($this->slots as $slot) {
$slot->invalidateCache();
}
}
......
......@@ -4,15 +4,14 @@
namespace Drupal\cache_register;
interface CacheRegisterInterface {
interface DrawerInterface {
/**
* Creates a new Slot in the register.
* Creates a new Slot in the Drawer.
*
* @note This does note create/populate the associated
* cache entry. You must implement $this->set($data)
* after instantiating the Slot to
* populate its cache entry.
* cache entry. You must implement $slot->set($data)
* to populate its cache entry.
*
* @param array|string $slot_ids
* The ID(s) to use for the slot's cache identifier.
......@@ -25,9 +24,9 @@ interface CacheRegisterInterface {
/**
* @return string
* The register's name.
* The drawer's name.
*/
public function getName();
public function id();
/**
* @return \Drupal\cache_register\SlotInterface[]
......
......@@ -16,7 +16,7 @@ class Slot implements SlotInterface {
/**
* The parent CacheRegister.
*
* @var \Drupal\cache_register\CacheRegisterInterface
* @var \Drupal\cache_register\DrawerInterface
*/
protected $parentCacheRegister;
......@@ -32,13 +32,13 @@ class Slot implements SlotInterface {
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* Cache backend.
* @param CacheRegisterInterface $parent_cache_register
* @param DrawerInterface $parent_cache_register
* The parent CacheRegister object.
* @param array|string $slot_ids
* The ID(s) to use for the slot's cache identifier.
*/
public function __construct(CacheBackendInterface $cache, CacheRegisterInterface $parent_cache_register, string $item_ids) {
public function __construct(CacheBackendInterface $cache, DrawerInterface $parent_cache_register, string $item_ids) {
$this->cache = $cache;
$this->parentCacheRegister = $parent_cache_register;
$this->cacheEntryId = $this->constructCacheEntryId($slot_ids);
......@@ -139,7 +139,7 @@ class Slot implements SlotInterface {
*/
private function constructCacheEntryId($slot_cache_ids) {
$cache_id = is_array($slot_cache_ids) ? implode('.', $slot_cache_ids) : $slot_cache_ids;
return "{$this->parentCacheRegister->getName()}:$cache_id";
return "{$this->parentCacheRegister->id()}:$cache_id";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment