1. Go to this page and download the library: Download humanmade/hm-swr-cache library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
humanmade / hm-swr-cache example snippets
// false is returned if the data isn't in the cache yet
$data = SwrCache\get(
$cache_key,
$cache_group,
__NAMESPACE__ . '\\my_callback',
$callback_args,
$cache_expiry
);
if ( ! $data) {
// handle initial empty cache load
}
function my_callback( array $args ) : WP_Error|array {
// Example validation handling and cache generation.
if ( ! isset( $args['url'] ) ) {
return new WP_Error( 'missing_arg', 'url' );
}
$data = example_api_request( $args );
if ( failed_validation( $data ) ) {
return new WP_Error( 'invalid_data', 'Data failed validation', $data );
}
return $data;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.