0

The documentation for wp_cache_set() says that if you pass in 0 for $expire (which is also the default), then it is cached for "as long as possible". How long is this? What determines it? Are we talking hours, days?

In my case: I have a very expensive SQL query on a multisite network of literally 100s of blogs, the result of which could be cached for weeks (really forever - could just manually flush it when needed). Should I use WordPress's cache or sort something out myself?

1 Answer 1

1

The WordPress object cache isn't a persistent cache, it's meant to cache data within a single page load, so "as long as possible" will never be longer than a single request.

Use the Transients API if you want to store your data across multiple page loads, or even simpler, just store it in an option manually.

4
  • 1
    +1 from me. Additional alternative is to use a plugin that convert wp object cahe in persistent cache using APC, memchache or similar. This is one
    – gmazzap
    Nov 8, 2013 at 23:41
  • Thanks for the info, makes sense. Apparently our heavily hacked/customized WP installation is already converting this cache into something persistent, because for me the cache is still there across multiple requests. Guess I need to dig into our venerable codebase to answer my question on this system...
    – tobek
    Nov 11, 2013 at 16:58
  • 1
    It can be persistent if you plug in a replacement for example for Redis.
    – Cranio
    Jun 14, 2016 at 10:12
  • Also some hosts (like WPEngine) have object cache built into their service
    – Philipp
    Apr 30, 2017 at 20:40

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.