The script exposes a
wp.cache object with the following methods:
add( key, data, group, expire )
replace( key, data, group, expire )
set( key, data, group, expire )
get( key, group, force )
remove( key, group )
incr( key, offset, group )
decr( key, offset, group )
switchToSite( siteId )
switchToNetwork( networkId )
addNetworkGroups( groups )
addGlobalGroups( groups )
addNonPersistentGroups( groups )
- Upload the entire
wp-cache-jsfolder to the
- Activate the plugin through the 'Plugins' menu in WordPress.
- Enqueue the script by using
wp_enqueue_script( 'wp-cache' )or by declaring it as a dependency to one of your scripts, such as
wp_enqueue_script( 'my-script', '/path/to/my/script.js', array( 'wp-cache' ) ).
How can I register my own cache implementation?
In order to do that, you need to create your own object which implements all of the methods mentioned in the Description section (except for
close() which can be optionally implemented), plus an additional
checkRequirements() method that should return
true|false depending on whether the client fulfills the requirements for this cache type.
You can then register your object using
wp.cache.registerImplementation( identifier, implementationObject, priority ) with
identifier being a unique identifier for your implementation and
priority being a numeric value to determine the priority in which to check for the implementation. The default
localStorage implementation has a priority of 10 and the
variableStorage implementation a priority of 100.