-
-
Save arfaram/412f9e6e21cf5b9e5381d356f28a01b6 to your computer and use it in GitHub Desktop.
Symfony 3 Cache Pool - SiteAccess awareness
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
# File: app/config/cache_pool/cache.redis.yml | |
# Reusable service for redis cache for use in tests/docker/platform.sh | |
services: | |
# create a new service | |
cache.adapter.redis.sa_aware: | |
class: eZ\DemoBundle\Cache\RedisSAAdapter | |
abstract: true | |
tags: | |
- { name: cache.pool, provider: "cache.default_redis_provider", clearer: "cache.default_clearer" } | |
- { name: monolog.logger, channel: "@cache" } | |
arguments: | |
- "" | |
- "" | |
- "0" | |
- "@ezpublish.siteaccess" | |
calls: | |
- { method: "setLogger", arguments: [ "@?logger" ] } | |
# Default configuration | |
cache.redis: | |
parent: cache.adapter.redis.sa_aware | |
tags: | |
- name: cache.pool | |
clearer: cache.app_clearer | |
# Examples from vendor/symfony/symfony/src/Symfony/Component/Cache/Traits/RedisTrait.php: | |
# redis://localhost:6379 | |
# redis://secret@example.com:1234/13 | |
# redis://secret@/var/run/redis.sock/13?persistent_id=4&class=Redis&timeout=3&retry_interval=3 | |
# provider: 'redis://%cache_dsn%' | |
provider: 'redis://localhost:6379' | |
# namespace: caribou |
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
<?php | |
/* | |
* This file is part of the Symfony package. | |
* | |
* (c) Fabien Potencier <fabien@symfony.com> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace eZ\DemoBundle\Cache; | |
use Symfony\Component\Cache\Adapter\AbstractAdapter; | |
use Symfony\Component\Cache\Traits\RedisTrait; | |
class RedisSAAdapter extends AbstractAdapter | |
{ | |
use RedisTrait; | |
/** | |
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient The redis client | |
* @param string $namespace The default namespace | |
* @param int $defaultLifetime The default lifetime | |
* @param \eZ\Publish\Core\MVC\Symfony\SiteAccess $siteAccessService | |
*/ | |
public function __construct($redisClient, $namespace = '', $defaultLifetime = 0, $siteAccessService) | |
{ | |
// maybe ugly but works ;) | |
if ($siteAccessService != null ) { | |
$namespace = $siteAccessService->name; | |
} | |
$this->init($redisClient, $namespace, $defaultLifetime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment