Convenient caching methods
use ThemePlate\Cache;
Cache::remember( 'unique_key', function() {
return expensive_task();
}, MINUTE_IN_SECONDS );
Cache::forget( 'unique_key' );
Cache::file( 'special_key', 'path_to_file' );
$processor = Cache::processor();
$processor->report( function( $output ) {
error_log( print_r( $output, true ) );
} );
function hourly_moment() {
return 'to remember ' . time();
}
Cache::remember( 'unique_key', 'hourly_moment', HOUR_IN_SECONDS );
<WP_HOME>/?tcs_refresh=<single_key>
<WP_HOME>/?tcs_refresh[]=<key1>&tcs_refresh[]=<key2>
works only when logged-in
Retrieve content from the cache or, if it doesn’t exist, execute $callback and its result is returned then saved
Retrieve and delete the cache
null
Like remember
but, uses the file contents and no expiration, automatically updates if the file is modified instead
Support for soft-expiration, Cache::remember
* and Cache::file
updates in the background
*Except for using anonymous function as callback (closure)