jump to navigation

New cache system March 14, 2006

Posted by rossoft in CakePHP.
trackback

In nightly version of cake, there is a new cache system. It can cache the views with cache helper, but you can cache your own data.

Example for caching your own data. You have the array $data. That array comes from the DB querying the model MyModel with parameter $id

$cacheName = “my_controller/$id”;
$data=cache($cacheName,null,’+1 hour’); //check for the value in the cache with a maximum of 1 hour old
if (!$data) //if isn’t on cache…
{
       $this->MyModel->id=$id;
       $data=$this->MyModel->read();
       cache($cacheName,$data); //save to cache
}

You have to create the dir /app/tmp/cache/my_controller (set the correct permissions)

Advertisements

Comments»

1. rossoft - April 15, 2006

If the data is an array or object, you must serialize it before write, and unserialize it after read


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: