1

I have a couple of pages that make calls to an external API to retrieve a value. Obviously, doing this every time the page loads is horribly slow.

What is the preferred way of cacheing this value for a limited amount of time (I only need it once every 24 hours).

If it matters, i will eventualy be extending the calls to make a large call to get a JSON object back, for another page, and will need to cache the whole object for 24 hours.

Things i've explored: Static file, just reading/writing to it Database table wp_cache? (there was some wording about how this isn't persistent across page reloads) wp total cache (i think it might be pro only)

i'm not hugely familiar with php, so i'm not sure if there's something built into the framework to handle this. or am i looking at this completely wrong? Would WP super cache (which caches entire pages and serves them statically) do what i need to do with minimal effort?

1 Answer 1

1

You want the Transients API: get_transient and set_transient (and get/set_site_transient).

These store values in the wp_options table with a namespace and expiry date, so they do persist through page reloads. (As does anything stored in the database, unless you explicitly create per-connection temporary tables.)

1
  • Thanks, that looks perfect.
    – Xander
    Commented Jun 5, 2019 at 10:47

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.