Developer Integration


This page is intended for ExpressionEngine® add-on developers. The following code sample will enable ExpressionEngine® developers to integrate CE Cache into their own add-ons.

Here’s a PHP snippet to get you started:

//check to see if CE Cache is an installed add-on
ee()->db->select( 'module_id' );
ee()->db->where( 'module_name', 'Ce_cache' );
$q = ee()->db->get( 'modules' );
$ce_cache_installed = ( $q->num_rows() > 0 );

if ( $ce_cache_installed )
    //include the cache_break class
    if ( ! class_exists( 'Ce_cache_break' ) )
        include PATH_THIRD . 'ce_cache/libraries/Ce_cache_break.php';

    //instantiate the class
    $cache_break = new Ce_cache_break();

    //the cache paths to remove or refresh
    $paths = array();

    //item tag names that you would like to remove or refresh
    $tags = array();

    //whether or not to refresh the local items after they are cleared
    $refresh = true;

    //the number of seconds to wait between refreshing (and deleting)
    //items. Only applicable if refreshing.
    $refresh_time = 1;

    $cache_break->break_cache( $paths, $tags, $refresh, $refresh_time );

Here’s the actual break_cache method signature for the Ce_cache_break class:

 * Allows the cache to manually be broken.
 * @param array $paths
 * @param array $tags
 * @param bool $refresh
 * @param int $refresh_time

public function break_cache( $paths = array(), $tags = array(), $refresh = true, $refresh_time = 1 )

Implementation Recommendation

One simple way of implementing cache breaking in your own add-ons, is to allow the user to indicate a tag name that corresponds with an event. Then when that event occurs, you can break the cached items that have that particular tag name.

For example, if you have an add-on where the user can update a menu, you could let them choose a tag name to use for an "update menu" event. If they specify a tag name of menu_updated, then anytime the menu is updated in your add-ons’s user interface, you could break the cache for all items that are tagged with that tag name. You could also allow them to choose whether or not to refresh the items, and the number of seconds to wait between deleting and refreshing the items.

Note: If you have any integration questions, please get in touch.