-
Notifications
You must be signed in to change notification settings - Fork 21
Home
Daniel M. Hendricks edited this page Aug 6, 2017
·
21 revisions
Welcome to the wiki page for wordpress-base-plugin.
I am adding to this as I can. More to come.
The caching class is intended to make it easy to reduce database calls and other resource-intensive operations.
- If object caching is enabled and the key exists, it will be return from cache.
- If either of the above are not true, it will fetch and return the current value.
$my_option = Cache::get_object( '_cache_key_name', function() {
return get_option( '_my_option_name' );
});
$my_option = Cache::get_object( '_cache_key_name', function() {
return carbon_get_theme_option( self::$prefix . '_my_option_name );
});
Additionally, the Plugin class contains a wrapper for retrieving Carbon Fields values:
$my_option = $this->get_plugin_option( '_my_option_name' );
There is also a Cache::flush()
function that you can use to clear the cache when the "Save Changes" button (or anywhere appropriate, such as on posts and pages). Example:
add_action('carbon_fields_theme_options_container_saved', array( '\\VendorName\\MyPlugin\\Cache', 'flush' ) );
An easy way to test object caching locally is to install Local by FlyWheel (which loads sites in virtual machines and also includes Redis) and:
- Create a new site.
- Install and activate the Redis Object Cache plugin.
- Click the Enable Object Cache button in Settings > Redis.
You can now enable/disable/flush the cache and test to make sure that everything is functioning as expected.