You can use W3TC or WP Supercache with fragment caching as seen in the following answers:
- W3 total cache – cache refresh programmatically
- How to exclude a specific template from being cached by a CDN
- Stylesheet switching and caching
If you’re using full page cache, obviously the user session variables will get tossed within the page render specifically. However, you can wrap your session bits in dynamic fragment tags as illustrated in the answers above and they should work just fine. You can also access your session information in hooks that precede the actual cache rendering if you need to do some sort of pre-processing for the dynamic bits.
Sourcing from @Rarst’s answer here for W3TC:
Example 1:
<!-- mfunc any PHP code --><!-- /mfunc -->
Example 2:
<!-- mfunc -->any PHP code<!-- /mfunc -->
Example 3:
<!--MFUNC -->
echo rand();
<!--/mfunc -->
Example 4:
<!-- mclude path/to/file.php --><!-- /mclude -->
Example 5:
<!-- mclude -->path/to/file.php<!-- /mclude -->
WordPress uses cookies rather than sessions. Why not use cookies instead? You can access cookies easily with JavaScript AND PHP. Session variables only have server-side access natively.