aequasi / cache-bundle
为 Symfony 2 创建缓存服务,这些服务也可以与 doctrines 三种缓存类型(元数据、结果和查询)一起使用。它还提供了对会话处理程序和路由器的支持。
Requires
- php: ~5.3
- doctrine/cache: ~1.3
- symfony/symfony: ~2.2
Requires (Dev)
- phpunit/phpunit: ~4.4
Suggests
- ext-memcached: Allows for caching with Memcached
- ext-redis: Allows for caching with Redis
This package is auto-updated.
Last update: 2023-11-05 19:08:31 UTC
README
此包已被 PHP-Cache 取代。去看看吧!
Aequasi cache-bundle 
Symfony 2 的缓存包
为 Symfony 2 创建缓存服务,这些服务也可以与 doctrines 三种缓存类型(元数据、结果和查询)一起使用。它还提供了对会话处理程序和路由器的支持。
您的项目需要相应的缓存扩展。
Redis 使用 php redis 扩展。
要求
- PHP >= 5.6, < 7.1
- Symfony >= 2.7, < 4.0
- Composer
安装
在您的项目根目录中运行以下命令,假设您的项目已设置 composer
composer.phar require aequasi/cache-bundle
将包添加到 app/AppKernel.php
$bundles( ... new Aequasi\Bundle\CacheBundle\AequasiCacheBundle(), ... );
然后添加您服务器的参数(可能在 config.yml 中)和选项
aequasi_cache: instances: default: persistent: true # Boolean or persistent_id namespace: mc type: memcached hosts: - { host: localhost, port: 11211 }
要查看所有配置选项,请运行 php app/console config:dump-reference aequasi_cache
以查看配置设置
Doctrine
此包允许您使用其服务进行 Doctrine 的元数据、结果和查询缓存方法。
如果您想将 doctrine 作为结果和查询缓存使用,请添加以下内容
aequasi_cache: doctrine: enabled: true metadata: instance: default entity_managers: [ default ] # the name of your entity_manager connection document_managers: [ default ] # the name of your document_manager connection result: instance: default entity_managers: [ default, read ] # you may specify multiple entity_managers query: instance: default entity_managers: [ default ]
会话
此包甚至允许您将您的会话数据存储在您的缓存集群中之一。要启用
aequasi_cache: session: enabled: true instance: default prefix: "session_" ttl: 7200
路由器
此包还提供了路由器缓存,以帮助加快该部分的速度。要启用
aequasi_cache: router: enabled: true instance: default
如果您更改了任何路由,您将需要清除缓存中的所有 route_* 键。
使用方法
要与此 doctrine 实体管理器一起使用,只需确保将 useResultCache
和/或 useQueryCache
设置为 true。如果您想使用用户缓存,只需像这样从容器中获取服务
// Change default to the name of your instance $cache = $container->get( 'aequasi_cache.instance.default' ); // Or $cache = $container->get( 'aequasi_cache.default' );
以下是一个服务使用示例
$cache = $this->get( 'aequasi_cache.instance.default' ); $item = $cache->getItem('test'); if ($item->isHit()) { var_dump($item->get()); return; } $cache->saveItem('test', $em->find('AcmeDemoBundle:User', 1), 3600);
需要帮助?
如果发现错误,请创建问题,或在推特上联系我:@aequasi