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

$this->EE->session->cache not working

Development and Programming

Ralph's avatar
Ralph
78 posts
13 years ago
Ralph's avatar Ralph

I’ve got some caching code in my plugin but it’s just not storing it. It’s adding the value to $this->EE->session->cache but the values is gone next time I hit the page. I’ve set my cache path to the right place but still no luck. I’m using WAMP 2.2 which might be the problem. Any ideas?

Config.php

$config['cache_path'] = 'C:/wamp/www/ee240/system/expressionengine/cache/';

My plugin:

if ($this->EE->session->cache('testcache', 'item')) {
 echo $this->EE->session->cache('testcache', 'item');
} else {
 $this->EE->session->set_cache('testcache', 'item','foo');
}
       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

$this->EE->session->cache does not cache data between requests. It would be better named $this->EE->request->cache. You can use $this->EE->set_flashdata to retrieve it on the next request, but the value will be cleared at the end of that request.

       
Ralph's avatar
Ralph
78 posts
13 years ago
Ralph's avatar Ralph

Ah I see, I misunderstood what Session cache did. I’m using $_SESSION instead which seems to do the job. However it would be ideal if there was something in EE that could globally cache some arrays for all users. Have you come across anything that can do this?

I’ve had a look at the Cache driver in CodeIgnitor here http://ellislab.com/codeigniter/user-guide/libraries/caching.html but I’m not sure how to get it working with my plugin as I don’t see how I can load CI drivers from an EE plugin.

       
Elliot Lewis's avatar
Elliot Lewis
49 posts
13 years ago
Elliot Lewis's avatar Elliot Lewis

I was going to post exactly the same question!

Checking through libraries/Session.php is does say:

Set Session Cache * * This method is a setter for the $cache class variable. * Note, this is not persistent across requests

So I’ve got the same question. How do you store persistant data across requests using an EE API?

       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

If you want an EE API then it would have to be http://ellislab.com/expressionengine/user-guide/development/reference/functions.html#set-cookie-name-string-value-string-expire-int

       
Elliot Lewis's avatar
Elliot Lewis
49 posts
13 years ago
Elliot Lewis's avatar Elliot Lewis

Thanks.

What’s the performance hit on that? If for instance every page request was checking persistent data, is a cookie a good idea?

In my case session vars was a good way to go as it’s per user specific. I needed to show random data on each page but make it less random! So I’m keeping a log of the last 10 entries and only showing a ‘random’ not seen recently entry.

       

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.