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?
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?
Share Improve this question asked Jun 5, 2019 at 10:27 XanderXander 1133 bronze badges1 Answer
Reset to default 1You 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.)