I want to bind a function to another function to cache its results.
Unfortunately it’s not a class, hence I think I cannot use Closures.
I.e. like a decorator in Python.
I want to do this because I cannot modify the function with patching an API code.
So I have a function which gets called very often which always does one SQL query:
function api_func() {
global $wpdb;
// ... do a query without caching ...
return $wpdb->get_col(...);
}
I want to surround this function by another function cache_func(), so that, whenever api_func() would be called, cache_func() gets called and can once cache the results.
Any ideas?
Thanks