How do I cache (core) API requests?

I’m am currently trialling the new (as of 2017) core API built into WordPress. My setup is reasonably simple:

 +---------+    +------+    +---------+
 |Wordpress|<-->|Guzzle|<-->|   App   |
 |(API)    |    +------+    |(PHPSlim)|
 +---------+                +---------+

Guzzle will be operating through a local loopback (/etc/hosts set up to see the api as a local resource).

The major players in the WP space for cacheing (WP Super Cache, W3, etc) don’t appear to do anything around the API. My understanding is that they essentially create snapshots of a rendered page and skip over any php (including db calls) for future requests.

So…

The question is, is it possible to apply a level of cache to the API calls in WP? The site is reasonably static, so ideally I don’t want to ping the DB for every request.

I have examined the headers returned by WP and no cacheing indicators are present. I have also considered using wp_cache functions or wp_transient functions, but both seem to be a misuse of their functionality.

Headers:
enter image description here

3 s
3

There is a cache plugin for WP Rest API with the name… WP Rest API Cache:

I’ve used it for small projects and helped me a lot.

Leave a Comment