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