Skip to content

Repository files navigation

PropelDataCacheBehavior

Build StatusLatest Stable VersionTotal Downloads

A Propel ORM behavior that provide auto data caching to your model.

  • support caching system APC, memcached and Redis (via DominoCacheStore)
  • auto caching and auto flush.

What's the difference Query Cache Behavior

Query Cache Behavior is caching transformation of a Query object (caching SQL code).
This Behavior is caching the results of database. (result data cache)

Requirements

Install

Composer

Add a dependency on snakano/propel-data-cache-behavior to your project's composer.json file.

{"require": {"snakano/propel-data-cache-behavior": "1.*"}}

Then, add the following configuration to your build.properties or propel.ini file:

propel.behavior.data_cache.class = lib.vendor.snakano.propel-data-cache-behavior.src.DataCacheBehavior

Configuration

schema.xml

<tablename="book">
<columnname="id"required="true"primaryKey="true"autoIncrement="true"type="INTEGER" />
<columnname="title"type="VARCHAR"required="true"primaryString="true" />
<behaviorname="data_cache">
<parametername="auto_cache"value="true" /> <!-- auto cache enable. default true (optional) -->
<parametername="backend"value="apc" /> <!-- cache system. "apc" or "memcache", default "apc". (optional) -->
<parametername="lifetime"value="3600" /> <!-- cache expire time (second). default 3600 (optional) -->
</behavior>
</table>

if use memcached.

Add the following configuration code to your project bootstraping file.

// 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)
)
)
);

Basic usage

$title = 'War And Peace';
BookQuery::create()
->filterByTitle($title)
->findOne(); // from Database
BookQuery::create()
->filterByTitle($title)
->findOne(); // from caching system

Disable cache

$title = 'Anna Karenina';
BookQuery::create()
->setCacheDisable() // disable cache
->filterByTitle($title)
->findOne();
  • setCacheEnable()
  • setCacheDisable()
  • isCacheEnable()
  • setLifetime($ttl)

When cache delete?

$book = newBook;
$book->setId(1);
$book->setTitle("War And Peace");
$book->save(); // purge cache.
  • expire cache lifetime.
  • call save() method.
  • call delete() method.
  • call BookPeer::doDeleteAll() method.
  • call BookPeer::purgeCache() method.

Manually delete cache.

$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.

License

MIT License

About

A Propel ORM behavior that provide auto data caching to your model.

Topics

Resources

Stars

20 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages