cache.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Psr\Cache\CacheItemPoolInterface;
  12. use Symfony\Component\Cache\Adapter\AbstractAdapter;
  13. use Symfony\Component\Cache\Adapter\AdapterInterface;
  14. use Symfony\Component\Cache\Adapter\ApcuAdapter;
  15. use Symfony\Component\Cache\Adapter\ArrayAdapter;
  16. use Symfony\Component\Cache\Adapter\DoctrineAdapter;
  17. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  18. use Symfony\Component\Cache\Adapter\MemcachedAdapter;
  19. use Symfony\Component\Cache\Adapter\PdoAdapter;
  20. use Symfony\Component\Cache\Adapter\ProxyAdapter;
  21. use Symfony\Component\Cache\Adapter\RedisAdapter;
  22. use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
  23. use Symfony\Component\Cache\Adapter\TagAwareAdapter;
  24. use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
  25. use Symfony\Component\Cache\Messenger\EarlyExpirationHandler;
  26. use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
  27. use Symfony\Contracts\Cache\CacheInterface;
  28. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  29. return static function (ContainerConfigurator $container) {
  30. $container->services()
  31. ->set('cache.app')
  32. ->parent('cache.adapter.filesystem')
  33. ->public()
  34. ->tag('cache.pool', ['clearer' => 'cache.app_clearer'])
  35. ->set('cache.app.taggable', TagAwareAdapter::class)
  36. ->args([service('cache.app')])
  37. ->set('cache.system')
  38. ->parent('cache.adapter.system')
  39. ->public()
  40. ->tag('cache.pool')
  41. ->set('cache.validator')
  42. ->parent('cache.system')
  43. ->private()
  44. ->tag('cache.pool')
  45. ->set('cache.serializer')
  46. ->parent('cache.system')
  47. ->private()
  48. ->tag('cache.pool')
  49. ->set('cache.annotations')
  50. ->parent('cache.system')
  51. ->private()
  52. ->tag('cache.pool')
  53. ->set('cache.property_info')
  54. ->parent('cache.system')
  55. ->private()
  56. ->tag('cache.pool')
  57. ->set('cache.messenger.restart_workers_signal')
  58. ->parent('cache.app')
  59. ->private()
  60. ->tag('cache.pool')
  61. ->set('cache.adapter.system', AdapterInterface::class)
  62. ->abstract()
  63. ->factory([AbstractAdapter::class, 'createSystemCache'])
  64. ->args([
  65. '', // namespace
  66. 0, // default lifetime
  67. abstract_arg('version'),
  68. sprintf('%s/pools', param('kernel.cache_dir')),
  69. service('logger')->ignoreOnInvalid(),
  70. ])
  71. ->tag('cache.pool', ['clearer' => 'cache.system_clearer', 'reset' => 'reset'])
  72. ->tag('monolog.logger', ['channel' => 'cache'])
  73. ->set('cache.adapter.apcu', ApcuAdapter::class)
  74. ->abstract()
  75. ->args([
  76. '', // namespace
  77. 0, // default lifetime
  78. abstract_arg('version'),
  79. ])
  80. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  81. ->tag('cache.pool', ['clearer' => 'cache.default_clearer', 'reset' => 'reset'])
  82. ->tag('monolog.logger', ['channel' => 'cache'])
  83. ->set('cache.adapter.doctrine', DoctrineAdapter::class)
  84. ->abstract()
  85. ->args([
  86. abstract_arg('Doctrine provider service'),
  87. '', // namespace
  88. 0, // default lifetime
  89. ])
  90. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  91. ->tag('cache.pool', [
  92. 'provider' => 'cache.default_doctrine_provider',
  93. 'clearer' => 'cache.default_clearer',
  94. 'reset' => 'reset',
  95. ])
  96. ->tag('monolog.logger', ['channel' => 'cache'])
  97. ->set('cache.adapter.filesystem', FilesystemAdapter::class)
  98. ->abstract()
  99. ->args([
  100. '', // namespace
  101. 0, // default lifetime
  102. sprintf('%s/pools', param('kernel.cache_dir')),
  103. service('cache.default_marshaller')->ignoreOnInvalid(),
  104. ])
  105. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  106. ->tag('cache.pool', ['clearer' => 'cache.default_clearer', 'reset' => 'reset'])
  107. ->tag('monolog.logger', ['channel' => 'cache'])
  108. ->set('cache.adapter.psr6', ProxyAdapter::class)
  109. ->abstract()
  110. ->args([
  111. abstract_arg('PSR-6 provider service'),
  112. '', // namespace
  113. 0, // default lifetime
  114. ])
  115. ->tag('cache.pool', [
  116. 'provider' => 'cache.default_psr6_provider',
  117. 'clearer' => 'cache.default_clearer',
  118. 'reset' => 'reset',
  119. ])
  120. ->set('cache.adapter.redis', RedisAdapter::class)
  121. ->abstract()
  122. ->args([
  123. abstract_arg('Redis connection service'),
  124. '', // namespace
  125. 0, // default lifetime
  126. service('cache.default_marshaller')->ignoreOnInvalid(),
  127. ])
  128. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  129. ->tag('cache.pool', [
  130. 'provider' => 'cache.default_redis_provider',
  131. 'clearer' => 'cache.default_clearer',
  132. 'reset' => 'reset',
  133. ])
  134. ->tag('monolog.logger', ['channel' => 'cache'])
  135. ->set('cache.adapter.redis_tag_aware', RedisTagAwareAdapter::class)
  136. ->abstract()
  137. ->args([
  138. abstract_arg('Redis connection service'),
  139. '', // namespace
  140. 0, // default lifetime
  141. service('cache.default_marshaller')->ignoreOnInvalid(),
  142. ])
  143. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  144. ->tag('cache.pool', [
  145. 'provider' => 'cache.default_redis_provider',
  146. 'clearer' => 'cache.default_clearer',
  147. 'reset' => 'reset',
  148. ])
  149. ->tag('monolog.logger', ['channel' => 'cache'])
  150. ->set('cache.adapter.memcached', MemcachedAdapter::class)
  151. ->abstract()
  152. ->args([
  153. abstract_arg('Memcached connection service'),
  154. '', // namespace
  155. 0, // default lifetime
  156. service('cache.default_marshaller')->ignoreOnInvalid(),
  157. ])
  158. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  159. ->tag('cache.pool', [
  160. 'provider' => 'cache.default_memcached_provider',
  161. 'clearer' => 'cache.default_clearer',
  162. 'reset' => 'reset',
  163. ])
  164. ->tag('monolog.logger', ['channel' => 'cache'])
  165. ->set('cache.adapter.pdo', PdoAdapter::class)
  166. ->abstract()
  167. ->args([
  168. abstract_arg('PDO connection service'),
  169. '', // namespace
  170. 0, // default lifetime
  171. [], // table options
  172. service('cache.default_marshaller')->ignoreOnInvalid(),
  173. ])
  174. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  175. ->tag('cache.pool', [
  176. 'provider' => 'cache.default_pdo_provider',
  177. 'clearer' => 'cache.default_clearer',
  178. 'reset' => 'reset',
  179. ])
  180. ->tag('monolog.logger', ['channel' => 'cache'])
  181. ->set('cache.adapter.array', ArrayAdapter::class)
  182. ->abstract()
  183. ->args([
  184. 0, // default lifetime
  185. ])
  186. ->call('setLogger', [service('logger')->ignoreOnInvalid()])
  187. ->tag('cache.pool', ['clearer' => 'cache.default_clearer', 'reset' => 'reset'])
  188. ->tag('monolog.logger', ['channel' => 'cache'])
  189. ->set('cache.default_marshaller', DefaultMarshaller::class)
  190. ->args([
  191. null, // use igbinary_serialize() when available
  192. ])
  193. ->set('cache.early_expiration_handler', EarlyExpirationHandler::class)
  194. ->args([
  195. service('reverse_container'),
  196. ])
  197. ->tag('messenger.message_handler')
  198. ->set('cache.default_clearer', Psr6CacheClearer::class)
  199. ->args([
  200. [],
  201. ])
  202. ->set('cache.system_clearer')
  203. ->parent('cache.default_clearer')
  204. ->public()
  205. ->set('cache.global_clearer')
  206. ->parent('cache.default_clearer')
  207. ->public()
  208. ->alias('cache.app_clearer', 'cache.default_clearer')
  209. ->public()
  210. ->alias(CacheItemPoolInterface::class, 'cache.app')
  211. ->alias(AdapterInterface::class, 'cache.app')
  212. ->alias(CacheInterface::class, 'cache.app')
  213. ->alias(TagAwareCacheInterface::class, 'cache.app.taggable')
  214. ;
  215. };