Delete Cached Models in CakePHP

This seems to bite me in the ass more often than not but any time you add a new model or adjust your associations, be sure to delete the cached ones from the /app/tmp/ folder. I'll get inexplicable errors about missing models and it always takes me a couple minutes to figure it out.

Published January 06, 2007
Categorized as CakePHP
Short URL:


7 Comments · RSS feed
Walker Hamilton said on January 06, 2007

If you've got cake running in development mode, it should check the db for updates to the table quite often. (That's that DESC *table name* that you see in the query output)

Jonathan Snook said on January 06, 2007

Walker: yeah, it's usually pretty good on a dev server. I tend to notice it more when I push stuff live and suddenly nothing loads.

Chris Adams said on January 06, 2007

I have gotten into the habit of emptying the cache after any update to a live server, granted there are some situations where this might be a problem but for most of my clients' sites the cache is more of a convenience than a necessity.

It's always fun wasting 5-6 minutes trying to figure out why an update failed, realizing the code was right all along.

Steve Oliveira said on January 06, 2007

Haha, ya this happens a lot. You keep wondering what's wrong with the code? Why isn't the update showing up properly? Then you realize it's something silly like forgetting to delete the cache.

Lance Willett said on January 09, 2007

Yep -- that's always a "gotcha" for me. Enough so that I've considered putting in a "clear model cache" button in the Admin area of CakePHP sites I work on... even just to save a few seconds clearing them via the command line. It's even more of a confusing gotcha because in debug mode things work smoothly (like Walker said already).

Matthew said on March 21, 2007

My usual trick to fix this is to enable debugging then disable it again, seems to clear the model caching.

primeminister said on August 25, 2008

Especially in models and persistent
$ rm -f /app/tmp/cache/models/cake_model_*
$ rm -f /app/tmp/cache/persistent/cake_core_*

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.