最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Preferred way of cacheing a value in php

programmeradmin3浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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.)

发布评论

评论列表(0)

  1. 暂无评论