wp query - 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 paramet

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!

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!

Share Improve this question edited Jul 30, 2019 at 7:19 T.Todua 5,8809 gold badges52 silver badges81 bronze badges asked Dec 30, 2016 at 6:02 TheBigKTheBigK 5691 gold badge7 silver badges15 bronze badges 4
  • 1 transients are unique if you give them unique names. you will load the same transient for all users if you request the same transient name for all users. – Milo Commented Dec 30, 2016 at 6:12
  • If you were to pick any one option from above, which one would you pick? – TheBigK Commented Dec 30, 2016 at 8:30
  • 1 There are no security risks to save the query in the cookie until you don't specify the database name, username, password or other sensitive information. Cookies do not involve communication and server processing, so it should be a bit faster. – Max Yudin Commented Dec 30, 2016 at 9:39
  • Using a transient in this case is a bad idea. You can read here: Everyone seems to misunderstand how transient expiration works, so the long and short of it is: transient expiration times are a maximum time. There is no minimum age. Transients might disappear one second after you set them, or 24 hours, but they will never be around after the expiration time. – nmr Commented Jul 30, 2019 at 7:29
Add a comment  | 

1 Answer 1

Reset to default 4

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745285384a4620526.html

相关推荐

  • wp query - 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 paramet

    12小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信