2017 © Pedro Peláez
 

library wp-cache-helper

Wrapper for WordPress caching functions

image

andrejcremoznik/wp-cache-helper

Wrapper for WordPress caching functions

  • Thursday, April 21, 2016
  • by andrejcremoznik
  • Repository
  • 0 Watchers
  • 0 Stars
  • 125 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 12 % Grown

The README.md

WP Cache Helper

A wrapper class for WordPress caching functions., (*1)

What is this?

WordPress provides some caching functions that make it needlessly hard to invalidate previously saved caches. The idea here is to version cache keys by appending a number. So instead of caching something with a key mycache it's cached as mycacheN where N is an integer we increment every time the cache needs to be invalidated (like in save_post hook)., (*2)

Installation

Copy the src/WpCacheHelper.php file to your project and require it require_once('path/to/WpCacheHelper.php');., (*3)

Or with composer: composer require andrejcremoznik/wp-cache-helper., (*4)

Usage

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();

Invalidate cache on post save / delete

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

The Versions

21/04 2016

dev-master

9999999-dev https://github.com/andrejcremoznik/wp-cache-helper

Wrapper for WordPress caching functions

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

by Andrej Čremožnik

21/04 2016

1.0.1

1.0.1.0 https://github.com/andrejcremoznik/wp-cache-helper

Wrapper for WordPress caching functions

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

by Andrej Čremožnik

21/04 2016

1.0.0

1.0.0.0 https://github.com/andrejcremoznik/wp-cache-helper

Wrapper for WordPress caching functions

  Sources   Download

MIT

The Requires

  • php >= 5.6

 

by Andrej Čremožnik