I’ve been trying to use the cache array to let multiple instances of my plugin on a page save some sql calls, per http://ellislab.com/expressionengine/user-guide/development/usage/session.html#cache.
Unfortunately each time the plugin is hit, it seems the $this->EE->session->cache array is empty once again.
What am I missing?
Ultra-simplified example:
class My_Class{
function My_Class(){
$this->EE =& get_instance();
$class = strtolower(get_class($this));
if (!isset($this->EE->session->cache[$class])){
$this->EE->session->cache[$class] = array();
$this->EE->session->cache[$class]['segments'] = 'test';
$this->return_data = 'flash cache is being set';
} else {
$this->return_data = 'success!';
}
}
}calling this plugin several times in a template gives me ‘flash cache is being set’ several times, no ‘success’.
have you tried it with a hardcoded value instead of $class? Doesn’t seem like it should make a difference but you never know til you try.
Aside from that your constructor looks basically like that of my String plugin, which has never had trouble setting or getting things in the cache:
class String {
var $return_data = "";
function String() {
$this->EE =& get_instance();
if(!isset($this->EE->session->cache['string'])) {
$this->EE->session->cache['string'] = array();
}
...
}
...
}Oh… wait a minute. If I use a tag multiple times with the same parameters does ExpressionEngine run it multiple times, or cache and repeat the results? If it only runs it once it would make sense if the cache doesn’t appear to change.
I just changed the params for the multiple tags and caching seems to work just fine.
I feel really stupid right now.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.