Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheManager ability to set custom cache storage. #1142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gam6itko
Copy link
Contributor

@gam6itko gam6itko commented Sep 7, 2024

Q A
Bugfix?
Breaks BC?
New feature? ✔️
Issues #...
Docs PR spiral/docs#...

User can set custom cache in bootloader.

Example for redis

use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Cache\CacheStorageRegistryInterface;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Psr16Cache;

final class RedisCacheBootloader extends Bootloader
{
    public function boot(CacheStorageRegistryInterface $cacheRegistry, EnvironmentInterface $env): void
    {
        $cacheRegistry->set(
            name: 'redis',
            cache: new Psr16Cache(
                pool: new RedisAdapter(
                    redis: RedisAdapter::createConnection($env->get('REDIS_DSN'))
                ),
            )
        );
    }
}

For now my cache config not looks pretty.

return [
    'default' => env('CACHE_STORAGE', 'redis'),

    'storages' => [
        'redis' => [
            'type' => Psr16Cache::class,
            'pool' => new Autowire(
                alias: RedisAdapter::class,
                parameters: [
                    'redis' => RedisAdapter::createConnection(env('REDIS_DSN')),
                ],
            ),
        ],
    ],
];

@roxblnfk roxblnfk requested a review from a team September 7, 2024 17:43
@roxblnfk roxblnfk added this to the 3.15 milestone Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants