[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7