We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Cache array not working

Development and Programming

hd 's avatar
hd 
156 posts
15 years ago
hd 's avatar hd 

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’.

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

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();
        }
        
        ...
    }

    ...
}
       
hd 's avatar
hd 
156 posts
15 years ago
hd 's avatar hd 

Yes, I have tried that, but for whatever reason it still isn’t working. I’ve used this for plugins before, and assumed that it was working… Now I’m tempted to go back and check them.

       
hd 's avatar
hd 
156 posts
15 years ago
hd 's avatar hd 

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.

       
Ingmar's avatar
Ingmar
29,245 posts
15 years ago
Ingmar's avatar Ingmar

Yes, identical tags are only run once. You need to change some little thing, anything, to make EE run it again.

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

http://emarketsouth.com/add-ons/string-plugin/template-tags/#random-parameter

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.