Tuesday, February 26, 2013

Cache::clearGroup in model and component building cache again

Hi

I have ran into a problem which drives me crazy :(

Ive a component which is used on every page to build the navigation for every individual user. The navigation is database driven so caching is a good idea - so far so good

The cache is built in the startup-callback of the component like so (package and agent is just an example):
 
public function initialize(Controller $controller) {
parent::initialize($controller);
$package = Cache::read($this->Auth->user('id'),'packages');

if (!$package) {
$agent = ClassRegistry::init('Agent')->find('first',array('conditions' => array('Agent.id' => $this->Auth->user('Company.agent_id'))));

if (!empty($agent)) {
Cache::write($this->Auth->user('id'), $agent['Package'],'packages');
}
}
}

This works as expected (if the cache file does not exist it would be generated).

Now, I would like to push the creation of the cache manually when a data-change happens. So Ive put an afterSave-callback in the model:

public function afterSave($created) {
Cache::clearGroup('packages');
}

This works too if I test this seperatly. But when I use this "together" with the component-callback I will get an error-message:

Warning (2): unlink(C:\xampp\htdocs\ebsst\tmp\cache\packages\ebsst_package_73): Permission denied [CORE\Cake\Cache\Engine\FileEngine.php, line 368]

The cache-file is not cleared though. I guess the file is locked by the file-system (Xampp on Windows 7) through the component. I am not sure about the order of these callbacks and how they interfere between models and components. So ive tried different callbacks in both - but no luck.

Do you have a hint to solve this problem or is this a complete false approach?

Thanks,
Frank

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: