3

I need to get my User info and when I call

$this->User->find('first', array('conditions' => array('User.id' => $user_id)));

the result contains just some of the fields.

I've currently updated database schema. On dev server it runs fine and returns all fields but on the production server those new fields are missing. Those servers have exactly the same configuration.

I've already tried to remove contents of app/tmp/cache/models and I am using File engine for caching.

The schema.php file is up to date, the contents of files in app/tmp/cache/models indicate that those fields are present but I have not been able to retreive them on the production server. The only difference perhaps is database and debug level. I've tried copying the database and using it with the dev server and that worked well.

I cannot obviously set debug to 2 on the production server.

Did anyone of you experience any sort of similar behavior?

PS I am using Cake 2.3.3

Elwhis
  • 1,241
  • 2
  • 23
  • 45
  • Are you sure you are not getting cached results ? If you add new records, do you get them in the find ? – Chris May 15 '13 at 15:31
  • I would say Chris is correct. remove the contents of tmp/cache/models and you will be up and running again. – timstermatic May 15 '13 at 15:39

3 Answers3

9

The answer was actually pretty simple. I had to remove not just the contents of app/tmp/models, but what actually made it work was removing of the contents of app/tmp/persistent.

Elwhis
  • 1,241
  • 2
  • 23
  • 45
  • 1
    You can also just turn debug on - this should force it to get fresh cache every time. – Dave May 15 '13 at 16:18
  • Yep, that would definitely solve it, but since it's a production server, this is not a possibility – Elwhis May 16 '13 at 09:15
  • It's just PHP - do a check for ?debug=1 and a valid IP - if so, set debug to 2 - otherwise 1...something like that. If you're dealing with bank accounts or something, that's probably not a great idea, but for most sites, I think it's ideal, as you can more easily determine issues among other things. – Dave May 16 '13 at 13:40
3

My answer differs from @Elwhis's slightly. I'm on Cake 2.4.5. For me there was no app/tmp/models directory or app/tmp/persistent. models and persistent were both under app/tmp/cache. Just like @Elwhis, looking in the app/tmp/cache/models directory showed the missing fields, so it was confusing.

To fix, I deleted all files from app/tmp/cache/persistent. Note that if you delete the directory itself, you'll get a 500 error from CakePHP.

I recommend adding the deletion of files in that directory to your deployment process.

Tyler Collier
  • 11,489
  • 9
  • 73
  • 80
0

Elwhis: The answer was actually pretty simple. I had to remove not just the contents of app/tmp/models, but what actually made it work was removing of the contents of app/tmp/persistent.

This still works to CakePHP 3, it fixed my problem!

Update 1

There are a simple way to clean up the cache with Bake CLI Tool, following below:

Cache Shell Command

To clear one cache config:

bin/cake cache clear

To clear all cache configs:

bin/cake cache clear_all

Matthew
  • 1,905
  • 3
  • 19
  • 26
dixavier27
  • 66
  • 8
  • Please don't add _"thanks"_ as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Once you [earn](http://meta.stackoverflow.com/q/146472) enough [reputation](http://stackoverflow.com/help/whats-reputation), you will gain privileges to [upvote answers](http://stackoverflow.com/help/privileges/vote-up) you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See [Why is voting important](http://stackoverflow.com/help/why-vote). – Matthew Jun 22 '19 at 16:33