I have a hybrid between a WordPress installation and another database with products data.
I have custom php codes which pull product data from the external database.
I want to cache everything that’s WordPress but let the custom php codes function normally.
Can this be done?
You can use W3TC or WP Supercache with fragment caching as seen in the following answers:
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:
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.