rickysu/cacheable-behavior-bundle
Composer 安装命令:
composer require rickysu/cacheable-behavior-bundle
包简介
Provide a propel1 smart cache behavior bundle for symfony 2
README 文档
README
Introduction
This is a symfony2 bundle for propel1 and provides a smart relation cache.
Features
- primary key and unique index query cache.
- one to one relation cache.
- one to many relation cache.
- many to many relation cache.
- auto detect single or composite key.
Requirements
- PHP 5.3.3 above
- rickysu/tagcache 0.1 above
Installation
editing the composer.json file in the root project.
Editing the composer.json under require: {} section add
"rickysu/cacheable-behavior-bundle": "0.1.*",
Install Bundle With Composer :
php composer.phar install
How to Use
setup config
app/config.yml
propel: path: "%kernel.root_dir%/../vendor/propel" phing_path: "%kernel.root_dir%/../vendor/phing" logging: %kernel.debug% dbal: driver: %database_driver% user: %database_user% password: %database_password% dsn: %database_driver%:host=%database_host%;dbname=%database_name%;charset=UTF8 behaviors: cacheable: RickySu\CacheableBehaviorBundle\Behavior\CacheableBehavior
add cacheable behavior in your schema.xml
retrieve data with primary key or unique index
<?xml version="1.0" encoding="UTF-8"?> <database name="myorm" defaultIdMethod="native" namespace="ORM\StoreBundle\Model"> <table name="member"> <behavior name="cacheable" /> <column name="id" type="bigint" primaryKey="true" autoIncrement="true" required="true"/> <column name="username" type="varchar" size="45" /> <column name="email" type="varchar" size="80" /> <unique> <unique-column name="username" /> <unique-column name="email" /> </unique> </table>
// filter by id =1 and build cache $Member=MemberPeer::retrieveByPk(1); $Member=MemberQuery::create()->findPk(1); //filter by username , email and build cache $Member=MemberPeer::retrieveByUsernameEmail('username','somebody@foo.com'); $Member=MemberQuery::create() ->filterByUsername('username') ->filterByEmail('somebody@foo.com') ->findOne(); //delete cache when save or delete $Member->save(); $Member->delete();
retrieve data with one to one relation
<?xml version="1.0" encoding="UTF-8"?> <database name="myorm" defaultIdMethod="native" namespace="ORM\StoreBundle\Model"> <table name="member"> <behavior name="cacheable" /> <column name="id" type="bigint" primaryKey="true" autoIncrement="true" required="true"/> <column name="username" type="varchar" size="45" /> <column name="email" type="varchar" size="80" /> </table> <table name="member_info"> <behavior name="cacheable" /> <column name="member_id" type="bigint" primaryKey="true" required="true"/> <column name="realname" type="varchar" size="45" /> <foreign-key foreignTable="member" onDelete="cascade" onUpdate="cascade"> <reference local="member_id" foreign="id" /> </foreign-key> </table>
retrieve data with one to many relation
<?xml version="1.0" encoding="UTF-8"?> <database name="myorm" defaultIdMethod="native" namespace="ORM\StoreBundle\Model"> <table name="category"> <behavior name="cacheable" /> <column name="id" type="bigint" primaryKey="true" autoIncrement="true" required="true"/> <column name="name" type="varchar" size="45" /> </table> <table name="article"> <behavior name="cacheable" /> <column name="id" type="bigint" primaryKey="true" required="true"/> <column name="category_id" type="bigint" /> <column name="title" type="varchar" size="128" /> <column name="content" type="longvarchar" /> <foreign-key foreignTable="category" onDelete="cascade" onUpdate="cascade"> <reference local="category_id" foreign="id" /> </foreign-key> </table>
retrieve data with one to many relation
<?xml version="1.0" encoding="UTF-8"?> <database name="myorm" defaultIdMethod="native" namespace="ORM\StoreBundle\Model"> <table name="member"> <behavior name="cacheable" /> <column name="id" type="bigint" primaryKey="true" autoIncrement="true" required="true"/> <column name="username" type="varchar" size="45" /> </table> <table name="group"> <behavior name="cacheable" /> <column name="id" type="bigint" primaryKey="true" required="true"/> <column name="groupname" type="varchar" size="45" /> </table> <table name="member_group" isCrossRef="true"> <behavior name="cacheable" /> <column name="member_id" type="bigint" primaryKey="true" required="true"/> <column name="group_id" type="bigint" primaryKey="true" required="true"/> <foreign-key foreignTable="member" onDelete="cascade" onUpdate="cascade"> <reference local="member_id" foreign="data_id" /> </foreign-key> <foreign-key foreignTable="group" onDelete="cascade" onUpdate="cascade"> <reference local="group_id" foreign="id" /> </foreign-key> </table>
TODO
clear cache when change relation mapping.
//set $Article belonds to $Category1 $Article->setCategory($Category1); $Article->save(); //set $Article belonds to $Category2 $Article->setCategory($Category2); $Article->save(); //we need to clear $Category1 and $Category2 reference cache.
Note
If your want use this behavior without symfony2 , please folow this demo.
LICENSE
MIT
rickysu/cacheable-behavior-bundle 适用场景与选型建议
rickysu/cacheable-behavior-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 4, 最近一次更新时间为 2012 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「propel」 「cache」 「rickysu」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rickysu/cacheable-behavior-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rickysu/cacheable-behavior-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rickysu/cacheable-behavior-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
This bundle provides cache with tags and controller cache
Provide a cache storage engine and delete with tags
Laravel 5 - Repositories to the database layer
Free as in freedom php component that generates configuration based hard coded locator
Propel integration of the Symfony Security ACL component.
统计信息
- 总下载量: 45
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-11-26