PHP code example of andrejcremoznik / wp-cache-helper

1. Go to this page and download the library: Download andrejcremoznik/wp-cache-helper 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/ */

    

andrejcremoznik / wp-cache-helper example snippets


use \AndrejCremoznik\WpCacheHelper\WpCacheHelper as Cache;

function do_something_expensive() {
    $cache = new Cache('data_key');
    $expensive_data = $cache->get();

    if ($expensive_data === false) {
        $expensive_data = get_expensive_data();
        $cache->set($expensive_data);
    }

    return $expensive_data;
}

echo do_something_expensive();

function invalidate_cache() {
    Cache::flush()
}
add_action('save_post',    'invalidate_cache');
add_action('deleted_post', 'invalidate_cache');