You are here

cacheexclude.module in CacheExclude 5

Same filename and directory in other branches
  1. 5.2 cacheexclude.module
  2. 6.2 cacheexclude.module
  3. 7.2 cacheexclude.module

File

cacheexclude.module
View source
<?php

function cacheexclude_menu($may_cache) {
  $items[] = array(
    'path' => 'admin/settings/cacheexclude',
    'title' => 'Cache Exclude',
    'description' => t('Configure pages to exclude from caching.'),
    'callback' => 'drupal_get_form',
    'callback arguments' => array(
      'cacheexclude_admin_settings',
    ),
    'access' => user_access('administer site configuration'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}
function cacheexclude_admin_settings() {
  $form['cacheexclude_list'] = array(
    '#type' => 'textarea',
    '#title' => t('Pages to exclude from caching'),
    '#default_value' => variable_get('cacheexclude_list', ''),
    '#width' => 40,
    '#height' => 10,
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_exit().
 */
function cacheexclude_exit($destination = NULL) {
  global $base_root;
  if ($destination == NULL) {
    $pages = trim(variable_get('cacheexclude_list', ''));
    if (strlen($pages) == 0) {
      return;
    }
    else {
      $pages = explode("\n", variable_get('cacheexclude_list', ''));
      $this_page = request_uri();
      foreach ($pages as $page) {
        $page = trim($page);
        if ($page && strstr($this_page, $page) !== false) {
          cache_clear_all($base_root . $this_page, 'cache_page');
          return;
        }
      }
    }
  }
}