Skip to content

Instantly share code, notes, and snippets.

@rbayliss
Created April 30, 2011 04:40
Show Gist options
  • Save rbayliss/949421 to your computer and use it in GitHub Desktop.
Save rbayliss/949421 to your computer and use it in GitHub Desktop.
Drush cache-disable and cache-enable commands.
<?php
function cache_drush_command() {
$items = array();
$items['cache-disable'] = array(
'description' => 'Disable caching.',
'arguments' => array(
'type' => 'Name of Caches to Disable'
),
'examples' => array(
'drush cache-disable css',
),
'aliases' => array('discache'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
$items['cache-enable'] = array(
'description' => 'Enable caching.',
'arguments' => array(
'type' => 'Name of Caches to Disable'
),
'examples' => array(
'drush cache-disable css',
),
'aliases' => array('encache'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
);
return $items;
}
function drush_cache_disable($type = NULL) {
drush_cache_set(0, $type);
}
function drush_cache_enable($type = NULL) {
drush_cache_set(1, $type);
}
function drush_cache_set($value, $type) {
$types = array();
$types['page'] = 'Page Cache';
$types['block'] = 'Block Cache';
$types['css'] = 'CSS Cache';
$types['js'] = 'JS Cache';
if(module_exists('devel')) {
$types['theme'] = 'Theme Registry';
}
$types['all'] = 'All';
if(!isset($types[$type])) {
$type = drush_choice($types, 'Select a Cache Type');
}
$variables = array();
switch($type) {
case 'page':
$variables['cache'] = $value;
break;
case 'block':
$variables['block_cache'] = $value;
break;
case 'css':
$variables['preprocess_css'] = $value;
break;
case 'js':
$variables['preprocess_js'] = $value;
break;
case 'theme':
$variables['devel_rebuild_theme_registry'] = ($value) ? 0 : 1;
break;
case 'all':
$variables['cache'] = $value;
$variables['block_cache'] = $value;
$variables['preprocess_css'] = $value;
$variables['preprocess_js'] = $value;
if(isset($types['theme'])) {
$variables['devel_rebuild_theme_registry'] = ($value) ? 0 : 1;
}
}
foreach($variables as $key => $val) {
drush_set_context('DRUSH_AFFIRMATIVE', TRUE);
$capture = drush_invoke('variable-set', $key, $val);
}
}
function drush_cache_types() {
return array(
'block_cache' => 'Block Cache',
'cache' => 'Page Cache',
'preprocess_css' => 'CSS Cache',
'preprocess_js' => 'JS Cache',
'all' => 'All',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment