Also posted the same question in StackOverflow: caching - Cached keys as "Array" or "Object" - Laminas Cache with Doctrine (PHP8.3) - Stack Overflow
Clean installation on PHP8.3. Using the following packages:
"doctrine/doctrine-orm-module": "^6.1",
"doctrine/doctrine-module": "^6.1",
"laminas/laminas-cache":"^3.12",
"laminas/laminas-cache-storage-adapter-redis":"^2.9"
Configuration:
...
'service_manager' => [
'factories' => [
'Service\Redis' => Service\Factory\RedisFactory::class,
],
],
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => \Doctrine\DBAL\Driver\PDO\MySQL\Driver::class,
'params' => [
'host' => 'localhost',
'port' => '3306',
'user' => 'db_user',
'password' => 'my_password',
'dbname' => 'db_skeleton',
'charset' => 'utf8mb4',
],
],
],
'driver' => [
'annotation_driver' => [
'class' => AttributeDriver::class,
'cache' => 'array',
'paths' => [
__DIR__ . '/../src/Entity',
],
],
'orm_default' => [
'drivers' => [
'Application\Entity' => 'annotation_driver',
],
],
],
'cache' => [
'redis' => [
'namespace' => 'skeleton',
'instance' => 'Service\Redis',
],
],
'configuration' => [
'orm_default' => [
'result_cache' => 'redis',
'query_cache' => 'redis',
'metadata_cache' => 'redis',
'hydration_cache' => 'redis',
'generate_proxies' => false,
]
]
],
...
“Service/Redis” → RedisFactory.php
<?php
namespace Application\Service\Factory;
use Laminas\Cache\Storage\Adapter\Redis;
use Psr\Container\ContainerInterface;
class RedisFactory
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$redis = new Redis([
'server' => ['host' => '127.0.0.1', 'port' => 6379],
]);
return $redis;
}
}
Works fine. Connecting to the Redis instance and creating the keys. However, the keys are stored as “Array” and “Object” as string and the query is always executed instead of fetching from the cache (which I don’t think the stored array/object strings will work anyway).
Could you help me figure out what I might be doing wrong?
Or, do you have any recommendations for a recent Doctrine/Laminas/Cache implementation (aside from the Doctrine ORM Module for Laminas documentation, which works with v5 but not fully with v6)?
Thanks in advance.