Custom Session Variables and Drupal Caching

deanx0r - October 17, 2008 - 04:02

I've got an issue across a few of my clients websites where we have used custom session variables in the page.tpl.php file which seemingly worked in previous Drupal versions, but it seems that in recent versions when Drupal performance caching is enabled that the values for the session variables are not retained. Once we turn off the performance caching there isn't a problem.

Any thoughts or suggestions?

I have the same issue as

triversedesigns - October 17, 2008 - 04:03

I have the same issue as well. Anyone got any info?

Triverse Designs, your online solutions made easy

ditto

Bacteria Man - November 16, 2008 - 17:14

I'm dealing with this issue. With normal caching enabled session variables aren't retaining their values for anonymous users. Disabling caching returns things to normal.

It's weird that more people aren't talking about this.

-------------------------------------------------------

"The sting in any rebuke is the truth." - Benjamin Franklin

they just havent made

deepM - December 31, 2008 - 01:38

they just havent made complex sites :)
i have same problem. and i used custom session for URL basis and when cached my whole site have gone crayze and url's got mixed. thinking of tryin cookies now to see does it make difference. was also thinking of using boost module but wondering what could there be used if here sessions are not working.

alternatives

Bacteria Man - December 31, 2008 - 03:37

I tried switching to cookies, but for some reason (it's been awhile) they didn't meet my needs.

I also looked at using the Session API module, but opted not to use it either.

The quick fix at the time was to disable caching, which works fine small low-traffic sites. However this issue really needs a concrete and long-term solution. I will revisit the whole thing the next time the need arises.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

i found some other post,

deepM - December 31, 2008 - 12:22

i found some other post, mentioning cookies with same problem so i didnt even try it. ofcourse on small site u dont need caching. well in fact you dont need drupal much. :-(
its logical for me, if drupal caches whole page it would cache variables and not recreate them anymore. what drupal needs then is more granular caching system. i would reckon that session API wouldnt help much as again all variables would be cached and not changed according to user. If somebody knows different please tell.

Depending on your application

Bacteria Man - December 31, 2008 - 20:27

Depending on your application needs you might be able to do something like Session Favorites.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

thanx man, all best in 2009.

deepM - January 1, 2009 - 16:36

thanx man, all best in 2009. nice find, hope i can make it work without problems with caching.

well not so good in my case

deepM - January 3, 2009 - 06:45

well not so good in my case after all :-(

anonymous user sessions

Bacteria Man - January 3, 2009 - 08:46

I'm not exactly sure what you're trying to do, but Session Favorites illustrates (with the use of Session API) how to track anonymous user sessions. It might be easier to simply have your users register. You can make it simple by turning of email validation, giving them instant access.

-------------------------------------------------------

"If you don't read the newspaper you are uninformed;
if you do read the newspaper you are misinformed."
-- Mark Twain

Nope

Kyle Skrinak - January 14, 2009 - 17:26

I tried the "easier" route and in my case it adds too many other complexities to manage and disabling email validation wasn't a snap, either, but I forget the details.

What if we use a php snippet to clear the cache immediately prior to the event that queries the session, although that feels like a sledgehammer for this thumbtack?

Then in my case i would

deepM - February 12, 2009 - 11:39

Then in my case i would clear cache all the time and probably just slow down server and site, not a good idea.

I have this issue as well.

r0t8 - January 20, 2009 - 01:17

I have this issue as well. There should be a hook to allow disabling of cache for specific page templates which need to modify custom session variables. For instance, I need to disable caching for my success page redirect which gets and deletes a custom session variable set by the form/module the page is redirected from. With caching enabled, that variable is not being deleted.

 
 

Drupal is a registered trademark of Dries Buytaert.