-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove dependency on thecodingmachine/cache-utils
The package seems to be unmaintained and prevents usage due to old psr/simple-cache. This removes the dependency on that package. The package provided cache clearance on Classes and ParentClasses when their files changed. This functionality can still be achieved by creating a custom implementation of `TheCodingMachine\GraphQLite\Utils\Cache\ClassBoundCacheContractFactoryInterface`. fixes #693
- Loading branch information
Showing
12 changed files
with
128 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Cache; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
use Psr\SimpleCache\InvalidArgumentException; | ||
use ReflectionClass; | ||
use function str_replace; | ||
|
||
class ClassBoundCacheContract implements ClassBoundCacheContractInterface | ||
{ | ||
private readonly string $cachePrefix; | ||
|
||
public function __construct(private readonly CacheInterface $classBoundCache, string $cachePrefix = '') | ||
{ | ||
$this->cachePrefix = str_replace(['\\', '{', '}', '(', ')', '/', '@', ':'], '_', $cachePrefix); | ||
} | ||
|
||
/** | ||
* @param string $key An optional key to differentiate between cache items attached to the same class. | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function get(ReflectionClass $reflectionClass, callable $resolver, string $key = '', int|null $ttl = null): mixed | ||
{ | ||
$cacheKey = $reflectionClass->getName() . '__' . $key; | ||
$cacheKey = $this->cachePrefix . str_replace(['\\', '{', '}', '(', ')', '/', '@', ':'], '_', $cacheKey); | ||
|
||
$item = $this->classBoundCache->get($cacheKey); | ||
if ($item !== null) { | ||
return $item; | ||
} | ||
|
||
$item = $resolver(); | ||
|
||
$this->classBoundCache->set($cacheKey, $item, $ttl); | ||
|
||
return $item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Cache; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
class ClassBoundCacheContractFactory implements ClassBoundCacheContractFactoryInterface | ||
{ | ||
public function make(CacheInterface $classBoundCache, string $cachePrefix = ''): ClassBoundCacheContractInterface | ||
{ | ||
return new ClassBoundCacheContract($classBoundCache, $cachePrefix); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Cache; | ||
|
||
use Psr\SimpleCache\CacheInterface; | ||
|
||
interface ClassBoundCacheContractFactoryInterface | ||
{ | ||
public function make(CacheInterface $classBoundCache, string $cachePrefix = ''): ClassBoundCacheContractInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Cache; | ||
|
||
use ReflectionClass; | ||
|
||
interface ClassBoundCacheContractInterface | ||
{ | ||
/** | ||
* @param string $key An optional key to differentiate between cache items attached to the same class. | ||
* | ||
* @return mixed | ||
*/ | ||
public function get(ReflectionClass $reflectionClass, callable $resolver, string $key = '', ?int $ttl = null); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters