• Resolved omii

    (@omii)


    Hi all,

    Very new to anything like this in WordPress. Perhaps I’m going about this the wrong way but I’d like to cache some request data to tone down network requests by caching the data.

    In typical PHP you could use a good old fashioned $_SESSION, or I’d just use JavaScript myself and write it to localStorage. Since I see relatively very little out there in regards to using $_SESSION with WordPress it just feels like I may be overlooking an API on the WP side.

    I do see sessions.php for user metadata but it seems to be more oriented toward expanding registered user data.

    The data that I’m trying to cache is page content that has nothing to do with the current using pulling it. It’s 100% public, content from a remote site.

    As best I can figure, if I use WP’s REST API to pull the data (in a plugin), save the request with an expiring timestamp in a table local to the WP site then I can pull that data for every request without hitting the API. Once the timestamp is exceeded I’d re-pull the data and update it.

    Is this nature outside of anything WP-friendly? Is there another class or path I should be considering for this? I’d like to keep the data pull server-side in PHP for this.

    Thanks for tips!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The best thing that you’d want to koo at is the Transients API. It’s a bit more versatile than sessions by themselves, and is built into WordPress natively.

    Thread Starter omii

    (@omii)

    Darn! This is exactly what I need, minus one thing. I use MultiSite on my setup.

    That isn’t to say I can’t simply give each site a unique transient slug, but just knowing every site will start littering multiple transient slugs in a large pool, especially memcached, the performance or encapsulation feels a bit breaching.

    Thanks for alerting me of transients however! I can think of a lot of uses for these.

    For a Netwok (multi-site) set up there’s also various site-specific functions available. eg: set_site_transient().

    Thread Starter omii

    (@omii)

    Ahhh, I read that entirely wrong! I read in the doc that the “site_” functions work the same on multisite except it’s network wide.

    So set_transient() is per-site and set_site_transient() is per-network.

    Thank you a million, this looks perfect!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘What's the latest on (session like) saving data between page loads?’ is closed to new replies.