snakano/propel-data-cache-behavior
一个为您的模型提供自动数据缓存的Propel ORM行为。
1.2.2
2016-01-12 04:03 UTC
Requires
- php: >=5.3.3
- propel/propel1: ~1.6
- snakano/cache-store: 1.*
README
一个为您的模型提供自动数据缓存的Propel ORM行为。
- 支持缓存系统APC、memcached和Redis(通过DominoCacheStore)
- 自动缓存和自动刷新。
查询缓存行为有什么区别?
查询缓存行为Query Cache Behavior是缓存查询对象的转换(缓存SQL代码)。
此行为缓存数据库的结果。(结果数据缓存)
要求
- Propel >= 1.6.0
- DominoCacheStore
安装
Composer
将snakano/propel-data-cache-behavior依赖添加到项目的composer.json文件中。
{ "require": { "snakano/propel-data-cache-behavior": "1.*" } }
然后,将以下配置添加到您的build.properties或propel.ini文件中
propel.behavior.data_cache.class = lib.vendor.snakano.propel-data-cache-behavior.src.DataCacheBehavior
配置
schema.xml
<table name="book"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="title" type="VARCHAR" required="true" primaryString="true" /> <behavior name="data_cache"> <parameter name="auto_cache" value="true" /> <!-- auto cache enable. default true (optional) --> <parameter name="backend" value="apc" /> <!-- cache system. "apc" or "memcache", default "apc". (optional) --> <parameter name="lifetime" value="3600" /> <!-- cache expire time (second). default 3600 (optional) --> </behavior> </table>
如果使用memcached。
将以下配置代码添加到项目的初始化文件中。
// configure memcached setting. Domino\CacheStore\Factory::setOption( array( 'storage' => 'memcached', 'prefix' => 'domino_test', 'default_ttl' => 360, 'servers' => array( array('server1', 11211, 20), array('server2', 11211, 80) ) ) );
基本用法
$title = 'War And Peace'; BookQuery::create() ->filterByTitle($title) ->findOne(); // from Database BookQuery::create() ->filterByTitle($title) ->findOne(); // from caching system
禁用缓存
$title = 'Anna Karenina'; BookQuery::create() ->setCacheDisable() // disable cache ->filterByTitle($title) ->findOne();
- setCacheEnable()
- setCacheDisable()
- isCacheEnable()
- setLifetime($ttl)
何时删除缓存?
$book = new Book; $book->setId(1); $book->setTitle("War And Peace"); $book->save(); // purge cache.
- 过期缓存生命周期。
- 调用
save()方法。 - 调用
delete()方法。 - 调用
BookPeer::doDeleteAll()方法。 - 调用
BookPeer::purgeCache()方法。
手动删除缓存。
$title = 'War And Peace'; $query = BookQuery::create(); $book = $query->filterByTitle($title)->findOne(); $cacheKey = $query->getCacheKey(); // get cache key. BookPeer::cacheDelete($cacheKey); // delete cache by key.
许可证
MIT许可证