[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/panels/plugins/cache/ -> simple.inc (source)

   1  <?php
   2  // $Id: simple.inc,v 1.1.2.5 2011/01/07 20:59:09 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Provides a simple time-based caching option for panel panes.
   7   */
   8  
   9  // Plugin definition
  10  $plugin = array(
  11    'title' => t("Simple cache"),
  12    'description' => t('Simple caching is a time-based cache. This is a hard limit, and once cached it will remain that way until the time limit expires.'),
  13    'cache get' => 'panels_simple_cache_get_cache',
  14    'cache set' => 'panels_simple_cache_set_cache',
  15    'cache clear' => 'panels_simple_cache_clear_cache',
  16    'settings form' => 'panels_simple_cache_settings_form',
  17    'settings form submit' => 'panels_simple_cache_settings_form_submit',
  18    'defaults' => array(
  19      'lifetime' => 15,
  20      'granularity' => 'none',
  21    ),
  22  );
  23  
  24  /**
  25   * Get cached content.
  26   */
  27  function panels_simple_cache_get_cache($conf, $display, $args, $contexts, $pane = NULL) {
  28    $cid = panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane);
  29    $cache = cache_get($cid, 'cache');
  30    if (!$cache) {
  31      return FALSE;
  32    }
  33  
  34    if ((time() - $cache->created) > $conf['lifetime']) {
  35      return FALSE;
  36    }
  37  
  38    return $cache->data;
  39  }
  40  
  41  /**
  42   * Set cached content.
  43   */
  44  function panels_simple_cache_set_cache($conf, $content, $display, $args, $contexts, $pane = NULL) {
  45    $cid = panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane);
  46    cache_set($cid, $content);
  47  }
  48  
  49  /**
  50   * Clear cached content.
  51   *
  52   * Cache clears are always for an entire display, regardless of arguments.
  53   */
  54  function panels_simple_cache_clear_cache($display) {
  55    $cid = 'panels_simple_cache';
  56  
  57    // This is used in case this is an in-code display, which means did will be something like 'new-1'.
  58    if (isset($display->owner) && isset($display->owner->id)) {
  59      $cid .= ':' . $display->owner->id;
  60    }
  61    $cid .= ':' . $display->did;
  62  
  63    cache_clear_all($cid, 'cache', TRUE);
  64  }
  65  
  66  /**
  67   * Figure out an id for our cache based upon input and settings.
  68   */
  69  function panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane) {
  70    $id = 'panels_simple_cache';
  71  
  72    // This is used in case this is an in-code display, which means did will be something like 'new-1'.
  73    if (isset($display->owner) && isset($display->owner->id)) {
  74      $id .= ':' . $display->owner->id;
  75    }
  76    $id .= ':' . $display->did;
  77  
  78    if ($pane) {
  79      $id .= ':' . $pane->pid;
  80    }
  81  
  82    if (user_access('view pane admin links')) {
  83      $id .= ':admin';
  84    }
  85  
  86    switch ($conf['granularity']) {
  87      case 'args':
  88        foreach ($args as $arg) {
  89          $id .= ':' . $arg;
  90        }
  91        break;
  92  
  93      case 'context':
  94        if (!is_array($contexts)) {
  95          $contexts = array($contexts);
  96        }
  97        foreach ($contexts as $context) {
  98          if (isset($context->argument)) {
  99            $id .= ':' . $context->argument;
 100          }
 101        }
 102    }
 103    if (module_exists('locale')) {
 104      global $language;
 105      $id .= ':' . $language->language;
 106    }
 107    
 108    if($pane->configuration['use_pager'] == 1) {
 109      $id .= ':p' . check_plain($_GET['page']);
 110    }
 111    
 112    return $id;
 113  }
 114  
 115  function panels_simple_cache_settings_form($conf, $display, $pid) {
 116    $options = drupal_map_assoc(array(15, 30, 60, 120, 180, 240, 300, 600, 900, 1200, 1800, 3600, 7200, 14400, 28800, 43200, 86400, 172800, 259200, 345600, 604800), 'format_interval');
 117    $form['lifetime'] = array(
 118      '#title' => t('Lifetime'),
 119      '#type' => 'select',
 120      '#options' => $options,
 121      '#default_value' => $conf['lifetime'],
 122    );
 123  
 124    $form['granularity'] = array(
 125      '#title' => t('Granularity'),
 126      '#type' => 'select',
 127      '#options' => array(
 128        'args' => t('Arguments'),
 129        'context' => t('Context'),
 130        'none' => t('None'),
 131      ),
 132      '#description' => t('If "arguments" are selected, this content will be cached per individual argument to the entire display; if "contexts" are selected, this content will be cached per unique context in the pane or display; if "neither" there will be only one cache for this pane.'),
 133      '#default_value' => $conf['granularity'],
 134    );
 135  
 136    return $form;
 137  }
 138  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7