snakano/propel-data-cache-behavior 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

snakano/propel-data-cache-behavior

Composer 安装命令:

composer require snakano/propel-data-cache-behavior

包简介

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

README 文档

README

Build Status Latest Stable Version Total 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

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

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 = new Book;
$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

统计信息

  • 总下载量: 44.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 5
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固