[CakePHP] disable model queries caching

Again a simple tip. CakePHP by default, in order to optimize performance, has a query caching system. This is a very cool feature but sometimes it may be self-defeating. For example when you do queries for Unit Testing.

In order to disable query caching, it’s enough to set the model cacheQueries variable to false. Setting it to true will re-enable queries caching.

You can disable it for the whole model “life-time” setting it during “design time”

<?php
class Project extends AppModel {
var $name = "Project";
var $customValidate = array("name");
var $cacheQueries = false;
...
?>

or you can temporarily disable it by calling the $this->Model->cacheQueries=false (use your model instead of “Model” 🙂 )

Here is some extract of code (pdf).

Advertisements

2 thoughts on “[CakePHP] disable model queries caching

  1. Hi I m new to cake php ,and i m reviewing a site based on cke php ,,so what this code will do

    class FeedsController extends AppController {
    var $cacheMode = ‘ignore’;
    }

    • It’s been a long time I’m not playing with cake and I guess that it has changed a lot in the meanwhile. BTW I guess it’s ignoring the cache.

      I’d suggest you to read the documentation and use the official channels (ML, IRC, …).

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