for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace leinonen\DataLoader;
final class CacheMap implements CacheMapInterface, \Countable
{
/**
* @var array
*/
private $cache = [];
* {@inheritdoc}
public function get($key)
$index = $this->findCacheIndexByKey($key);
if ($index === null) {
return false;
}
return $this->cache[$index]['value'];
public function set($key, $value): void
$cacheEntry = [
'key' => $key,
'value' => $value,
];
if ($index !== null) {
$this->cache[$index] = $cacheEntry;
return;
$this->cache[] = $cacheEntry;
public function delete($key): void
unset($this->cache[$index]);
public function clear(): void
$this->cache = [];
public function count(): int
return \count($this->cache);
* Returns the index of the value from the cache array with the given key.
*
* @param mixed $cacheKey
* @return mixed
private function findCacheIndexByKey($cacheKey)
foreach ($this->cache as $index => $data) {
if ($data['key'] === $cacheKey) {
return $index;