Coder Social home page Coder Social logo

shurikn / propeldatacachebehavior Goto Github PK

View Code? Open in Web Editor NEW

This project forked from snakano/propeldatacachebehavior

0.0 2.0 0.0 315 KB

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

License: MIT License

Ruby 1.02% PHP 98.98%

propeldatacachebehavior's Introduction

PropelDataCacheBehavior

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 = vendor.propel-datacache-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="backend" value="apc" />     <!-- cache system. "apc" or "memcache", default "apc". (optional) -->
    <parameter name="lifetime" value="3600" />   <!-- cache expire time (second). default 3600 (optional) -->
    <parameter name="auto_cache" value="true" /> <!-- auto cache enable. default true (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

propeldatacachebehavior's People

Contributors

lbarulski avatar nibsirahsieu avatar snakano avatar staabm avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.