lavoiesl / doctrine-cache-detector
此包已被废弃,不再维护。未建议替代包。
库用于检测可用的 Doctrine 缓存系统,并确定最佳使用方案。
v2.0
2014-04-07 20:39 UTC
Requires
Requires (Dev)
Suggests
- lavoiesl/apc-polyfill: Tiny script to create APC aliases when APCu is present but APC support is not emulated.
- lavoiesl/doctrine-cache-provider: Library to add a Doctrine Provider to allow Doctrine Cache to connect to databases.
This package is not auto-updated.
Last update: 2022-07-18 08:51:57 UTC
README
使用 Doctrine\Common\Cache 检测所有可用的缓存层。
还包含一些性能数据,以选择最佳的缓存系统。
这在不同的开发环境中非常有用。
使用方法
列出所有支持的缓存
<?php use Lavoiesl\Doctrine\CacheDetector\CacheDetector; $cache_detector = new CacheDetector; $detectors = $cache_detector->getSupportedDetectors(); /** * [Apc, Filesystem, PhpFile, etc.] */ print_r(array_keys($detectors)); // Doctrine\Common\Cache\ApcCache $cache = $detectors['Apc']->getCache(); ?>
提供连接选项
为检测器提供选项,请参阅每个检测器的详细信息。
<?php $cache_detector->setConfig('Redis', array('port' => 1234)); // or $cache_detector->setConfigs(array( 'Redis' => array('port' => 1234), )); ?>
选择最佳缓存系统
这将自动选择在持久性级别上性能最佳的缓存系统。
在本地机器上,ArrayCache 就足够了。在生产环境中,您可能需要要求使用分布式缓存。
<?php use Lavoiesl\Doctrine\CacheDetector\Detector\AbstractDetector; $array_cache = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_REQUEST)->getCache(); $apc_cache = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_LOCAL_SERVICE)->getCache(); $file_cache = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_LOCAL_PERMANENT)->getCache(); $memcache_cache = $cache_detector->selectBest(AbstractDetector::PERSISTANCE_DISTRIBUTED)->getCache(); ?>
待办事项
- 添加对 MongoDB、Couchbase 和 Riak 的支持。
- 添加更好的性能数据。