wp_transients | wp_object_cache VS SESSIONS & Cookies?

My plugin requires me to save query data for some time. The data isn’t big as such; just a couple of search parameters entered by the user so that I can use them across pagination.

I’ve figured out following ways to do this:

  1. Setting up session_start() either in wp_config OR hooking it up to ‘init’ and then storing my data in $_SESSION. Then destroying the session when user logs out

  2. Using either set_transient or wp_cache_set; which will store the data in the database; but with expiration time. Of course, I can have my code delete the transient to avoid bloat in the database.

Question: Are the transients shared by all the users visiting a site? So let’s say user1 sets transient data; will it be available to user2?

  1. Use Cookies. This perhaps is the same as using $_SESSION; but I’m wondering if there’d be any security issues with this.

Which approach do you suggest? If there’s any other more efficient approach – I’d like to know about it as well.

Thank you in advance!

1 Answer
1

set_transient() using wp_cache_set() and mysql database. WP Cache API using $GLOBAL(global session for application).

Cookies and Session saves data only for one current user(cookies in browser, sessions on backend).

I think better using set_transient(), it has nice hooks and save all data global, even on site disabled cache.

Leave a Comment