cache / doctrine-adapter-bundle
0.2.0
2016-01-02 22:47 UTC
Requires
- php: ^5.5|^7
- cache/doctrine-adapter: ^0.2
- symfony/framework-bundle: ^2.6|^3.0
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: 0.7.*
- phpunit/phpunit: 5.0.*|^4.0
Suggests
- ext-memcached: Allows for caching with Memcached
- ext-redis: Allows for caching with Redis
This package is auto-updated.
Last update: 2022-02-01 12:53:30 UTC
README
Doctrine 适配器包
此包帮助您配置和注册 PSR-6 缓存服务。包使用 Doctrine 作为缓存实现,并通过 DoctrineAdapter 来使其符合 PSR-6 规范。
安装
在项目根目录下运行以下命令,假设您的项目已设置 composer
composer require cache/doctrine-adapter-bundle
将包添加到 app/AppKernel.php
$bundles( // ... new Cache\Adapter\DoctrineAdapterBundle\DoctrineAdapterBundle(), // ... );
配置
cache_adapter_doctrine: providers: acme_memcached: type: memcached persistent: true # Boolean or persistent_id namespace: mc hosts: - { host: localhost, port: 11211 } acme_redis: type: redis hosts: main: host: 127.0.0.1 port: 6379 acme_file_system_cache: type: file_system extension: '.fsc' directory: '%kernel.root_dir%/var/storage/fs_cache/' acme_php_file_cache: type: php_file extension: '.cache' directory: '%kernel.root_dir%/var/storage/' acme_array_cache: type: array acme_apc_cache: type: apc namespace: my_ns
使用
使用以下配置时,您将获得一个 ID 为 cache.provider.acme_apc_cache
的服务。
cache_adapter_doctrine: providers: acme_apc_cache: type: apc namespace: my_ns
将新服务用作任何 PSR-6 缓存。
/** @var CacheItemPoolInterface $cache */ $cache = $this->container->get('cache.provider.acme_apc_cache'); // Or $cache = $this->container->get('cache'); // This is either the `default` provider, or the first provider in the config /** @var CacheItemInterface $item */ $item = $cache->getItem('cache-key'); $item->set('foobar'); $item->expiresAfter(3600); $cache->save($item);