|
37 | 37 | **Adapter**
|
38 | 38 | An adapter is a *template* that you use to create Pools.
|
39 | 39 | **Provider**
|
40 |
| - A provider is the DSN connection to the actual storage. |
| 40 | + A provider is a service that some adapters are using to connect to the storage. |
| 41 | + Redis and Memcached are example of such adapters. If a DSN is used as the |
| 42 | + provider then a service is automatically created. |
41 | 43 |
|
42 | 44 | There are two pools that are always enabled by default. They are ``cache.app`` and
|
43 | 45 | ``cache.system``. The system cache is use for things like annotations, serializer,
|
@@ -315,6 +317,83 @@ For advanced configurations it could sometimes be useful to use a pool as an ada
|
315 | 317 | ],
|
316 | 318 | ]);
|
317 | 319 |
|
| 320 | +Custom Provider Options |
| 321 | +----------------------- |
| 322 | + |
| 323 | +Some providers have specific options that could be configured. The |
| 324 | +:doc:`RedisAdapter </components/cache/adapters/redis_adapter>` allows you to create |
| 325 | +providers with option ``timeout``, ``retry_interval`` etc. To use these options with non-default |
| 326 | +values you need to create your own ``\Redis`` provider and use that when configuring |
| 327 | +the pool. |
| 328 | + |
| 329 | +.. configuration-block:: |
| 330 | + |
| 331 | + .. code-block:: yaml |
| 332 | +
|
| 333 | + # config/packages/cache.yaml |
| 334 | + framework: |
| 335 | + cache: |
| 336 | + pools: |
| 337 | + cache.my_redis: |
| 338 | + adapter: cache.adapter.redis |
| 339 | + provider: app.my_custom_redis_provider |
| 340 | +
|
| 341 | + services: |
| 342 | + app.my_custom_redis_provider: |
| 343 | + class: \Redis |
| 344 | + factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection'] |
| 345 | + arguments: |
| 346 | + - 'redis://localhost' |
| 347 | + - [ retry_interval: 2, timeout: 10 ] |
| 348 | +
|
| 349 | +.. code-block:: xml |
| 350 | +
|
| 351 | + <!-- config/packages/cache.xml --> |
| 352 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 353 | + <container xmlns="http://symfony.com/schema/dic/services" |
| 354 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 355 | + xmlns:framework="http://symfony.com/schema/dic/symfony" |
| 356 | + xsi:schemaLocation="http://symfony.com/schema/dic/services |
| 357 | + https://symfony.com/schema/dic/services/services-1.0.xsd"> |
| 358 | +
|
| 359 | + <framework:config> |
| 360 | + <framework:cache> |
| 361 | + <framework:pool name="cache.my_redis" adapter="cache.adapter.redis" provider="app.my_custom_redis_provider"/> |
| 362 | + </framework:cache> |
| 363 | + </framework:config> |
| 364 | +
|
| 365 | + <services> |
| 366 | + <service id="app.my_custom_redis_provider" class="\Redis"> |
| 367 | + <argument>redis://localhost</argument> |
| 368 | + <argument type="collection"> |
| 369 | + <argument key="retry_interval">2</argument> |
| 370 | + <argument key="timeout">10</argument> |
| 371 | + </argument> |
| 372 | + </service> |
| 373 | + </services> |
| 374 | + </container> |
| 375 | +
|
| 376 | + .. code-block:: php |
| 377 | +
|
| 378 | + // config/packages/cache.php |
| 379 | + $container->loadFromExtension('framework', [ |
| 380 | + 'cache' => [ |
| 381 | + 'pools' => [ |
| 382 | + 'cache.my_redis' => [ |
| 383 | + 'adapter' => 'cache.adapter.redis', |
| 384 | + 'provider' => 'app.my_custom_redis_provider', |
| 385 | + ], |
| 386 | + ], |
| 387 | + ], |
| 388 | + ]); |
| 389 | +
|
| 390 | + $container->getDefinition('app.my_custom_redis_provider', \Redis::class) |
| 391 | + ->addArgument('redis://localhost') |
| 392 | + ->addArgument([ |
| 393 | + 'retry_interval' => 2, |
| 394 | + 'timeout' => 10 |
| 395 | + ]); |
| 396 | +
|
318 | 397 | Creating a Cache Chain
|
319 | 398 | ----------------------
|
320 | 399 |
|
|
0 commit comments