Skip to content

Instantly share code, notes, and snippets.

@domstubbs
Created November 23, 2012 09:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domstubbs/4134669 to your computer and use it in GitHub Desktop.
Save domstubbs/4134669 to your computer and use it in GitHub Desktop.
Stash cache breaker extension for EE2 (See https://github.com/domstubbs/ee-stash-breaker for updates)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExpressionEngine - by EllisLab
*
* @package ExpressionEngine
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc.
* @license http://expressionengine.com/user_guide/license.html
* @link http://expressionengine.com
* @since Version 2.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* Stash Breaker Extension
*
* @package ExpressionEngine
* @subpackage Addons
* @category Extension
* @author Dom Stubbs
* @link http://www.vayadesign.net
*/
class Stash_breaker_ext {
public $settings = array();
public $description = 'Automatically flush site-scoped Stashes when entries are updated. Requires Stash 2.3.0 or greater.';
public $docs_url = '';
public $name = 'Stash Breaker';
public $settings_exist = 'n';
public $version = '0.1';
/**
* Constructor
*
* @param mixed Settings array or empty string if none exist.
*/
public function __construct($settings = '')
{
$this->EE =& get_instance();
$this->settings = $settings;
}
// ----------------------------------------------------------------------
/**
* Activate Extension
*
* This function enters the extension into the exp_extensions table
*
* @see http://codeigniter.com/user_guide/database/index.html for
* more information on the db class.
*
* @return void
*/
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$hooks = array(
'entry_submission_end',
'low_variables_post_save',
'low_variables_delete'
);
foreach($hooks as $hook)
{
$data = array(
'class' => __CLASS__,
'method' => 'flush_site_stashes',
'hook' => $hook,
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
}
}
// ----------------------------------------------------------------------
/**
* Flush Site Stashes
*
* Called by $hooks, removes all globally-scoped stashes
*/
public function flush_site_stashes()
{
if ( ! class_exists('Stash'))
{
include_once PATH_THIRD . 'stash/mod.stash.php';
}
$params = array(
'scope' => 'site'
);
Stash::destroy($params);
}
// ----------------------------------------------------------------------
/**
* Disable Extension
*
* This method removes information from the exp_extensions table
*
* @return void
*/
function disable_extension()
{
$this->EE->db->where('class', __CLASS__);
$this->EE->db->delete('extensions');
}
// ----------------------------------------------------------------------
/**
* Update Extension
*
* This function performs any necessary db updates when the extension
* page is visited
*
* @return mixed void on update / false if none
*/
function update_extension($current = '')
{
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
}
// ----------------------------------------------------------------------
}
/* End of file ext.stash_breaker.php */
/* Location: /system/expressionengine/third_party/stash_breaker/ext.stash_breaker.php */
@jeromecoupe
Copy link

Using this extension as a stopgap measure until The @croxton comes up with a fully fledged solution, which he is currently working on. This works like a charm for me. I only added a couple of hooks to cover most basic use cases.

$hooks = array(
'entry_submission_end',
'delete_entries_end',
'update_multi_entries_start',
'low_variables_post_save',
'low_variables_delete'
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment