0

Is there a way to cache data on user's browser. I need to save a object that depend from user. I used wp_cache_set, but I notice that it expire after one request. Is there a way to save this data for each request?

3
  • How are you using wp_cache_set() right now? You may want to use the Transients API instead if you want to be sure that your data is cached.
    – janh
    Nov 13, 2017 at 9:13
  • @janh Yes, I'm using wp_cache_set now. But transient create an option temporary on DB, so if two user logged in, both share the same option. In that way, data cache on server, not on user's browser.
    – Mintendo
    Nov 13, 2017 at 19:17
  • Either add a unique identifier to the cache key, or maybe use PHP sessions?
    – janh
    Nov 13, 2017 at 19:29

1 Answer 1

0

wp_cache_* methods are cached in either php memory or an object cache ( if available ) . It will never be available to be saved in the browser.

If you want to save it on the browser side, you'll need to use JavaScript. Local or Session storage are great for that https://caniuse.com/#feat=namevalue-storage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.