kozz / yii-doctrine-cache
Yii 1 的 Doctrine 缓存工厂
1.0.0
2015-01-31 16:22 UTC
This package is not auto-updated.
Last update: 2024-09-14 16:08:27 UTC
README
Yii 中 Doctrine 缓存的代理
何时使用
YiiDoctrineCache 实现 Doctrine\Common\Cache\Cache 接口,因此与所有需要 Doctrine 缓存的库完全兼容,例如:
- Doctrine 注释读取器
- Symfony 验证器
- JMS 序列化器
工作原理
YiiDoctrineCache 根据 Yii 缓存配置加载最合适的 Doctrine 缓存实现
Doctrine\Common\Cache\MemcachedCacheDoctrine\Common\Cache\MemcacheCacheDoctrine\Common\Cache\ArrayCache
优势
YiiDoctrineCache 在底层使用代理设计模式,因此每次调用 new YiiDoctrineCache() 时,您都始终拥有相同的缓存实例,即使 Doctrine 的 ArrayCache 被选中
//SomeFile.php use Kozz\Yii1\Cache\YiiDoctrineCache; $cache = new YiiDoctrineCache(); $cache->save('id', 'value'); //SomeOtherFile.php use Kozz\Yii1\Cache\YiiDoctrineCache; $cache = new YiiDoctrineCache(); $cache->fetch('id'); // 'value'
参考
方法
fetch($id) - 从缓存中获取条目
contains($id) - 测试缓存中是否存在条目
save($id, $data, $lifeTime = false) - 将数据放入缓存
delete($id) - 删除缓存条目