Open kauaicreative opened 3 years ago
I've been concidering different ways of adding cache support for components in general as there could be need to:
a) cache response for the same request b) cache response in transient for a short time
For the same request version static variable might be a good solution as the variable scope is more protected than globals but gives a similar flexibility. To keep track of variations of same component you could json encode the $args variable as it should most of the time hold the changing bits of the component (of course there are some "not so dumb" components like hero that uses the context insted of just arguments).
For the generic solution we could either have some reserved arguments like '__cache-transient' => 15 * MINUTE_IN_SECONDS
or use PHP7 chaining like Component::transient(['expire' => 3600])::render(['foo' => 'bar]);
So I'd like to fix this issue after implementing a generic solution to caching and in the mean time something like that does work. WP does have some built-in DB caching that might actually prevent doing double DB queries already (would need to be tested) and if there is some kind of page cache in place, this should really cause much issues although not optimal.
Good ideas! And learning about the wp_cache_get() and set functions right now.
Here is my fix: