00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 function panels_simple_cache_menu($may_cache) {
00015 if ($may_cache) {
00016 $items[] = array(
00017 'path' => 'admin/panels/simple-cache',
00018 'title' => t('Simple cache'),
00019 'access' => user_access('access administration pages') && user_access('use panels caching features'),
00020 'type' => MENU_NORMAL_ITEM,
00021 'callback' => 'panels_simple_cache_admin',
00022 'description' => t('Information about Panels simple cache.'),
00023 );
00024 return $items;
00025 }
00026 }
00027
00028
00029
00030
00031 function panels_simple_cache_admin() {
00032 $output = '<p>';
00033 $output .= t('Panels simple cache does not have a normal administrative UI, such as panels pages or mini panels. With this module, you are given the option to add caching features to any panel display in panel pages, mini panels, panel nodes or any other displays provided by other modules or plugins. These options are available as an icon on each pane of the edit content pane.');
00034 $output .= '</p><p>';
00035 $output .= t('This module provides only very simple, time-based caching; it is not at all suitable if your content will change at all per user (and this can mean administrative additions that are just visible to you) as all users will see the same content; it is provided mostly as a reference implementation for other, smarter caching modules.');
00036 $output .= '</p>';
00037 return $output;
00038 }
00039
00040
00041
00042
00043 function panels_simple_cache_panels_cache() {
00044 $cache['simple'] = array(
00045 'title' => t("Simple cache"),
00046 '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.'),
00047 'cache get' => 'panels_simple_cache_get_cache',
00048 'cache set' => 'panels_simple_cache_set_cache',
00049 'cache clear' => 'panels_simple_cache_clear_cache',
00050 'settings form' => 'panels_simple_cache_settings_form',
00051 'settings form submit' => 'panels_simple_cache_settings_form_submit',
00052 );
00053 return $cache;
00054 }
00055
00056
00057
00058
00059 function panels_simple_cache_get_cache($conf, $display, $args, $contexts, $pane = NULL) {
00060 $cid = panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane);
00061 $cache = cache_get($cid, 'cache');
00062 if (!$cache) {
00063 return FALSE;
00064 }
00065
00066 if ((time() - $cache->created) > $conf['lifetime']) {
00067 return FALSE;
00068 }
00069
00070 return unserialize($cache->data);
00071 }
00072
00073
00074
00075
00076 function panels_simple_cache_set_cache($conf, $content, $display, $args, $contexts, $pane = NULL) {
00077 $cid = panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane);
00078 cache_set($cid, 'cache', serialize($content));
00079 }
00080
00081
00082
00083
00084
00085
00086 function panels_simple_cache_clear_cache($display) {
00087 $cid = 'panels_simple_cache';
00088
00089
00090 if (isset($display->owner) && isset($display->owner->id)) {
00091 $cid .= ':' . $display->owner->id;
00092 }
00093 $cid .= ':' . $display->did;
00094
00095 cache_clear_all($cid, 'cache', TRUE);
00096 }
00097
00098
00099
00100
00101 function panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane) {
00102 $id = 'panels_simple_cache';
00103
00104
00105 if (isset($display->owner) && isset($display->owner->id)) {
00106 $id .= ':' . $display->owner->id;
00107 }
00108 $id .= ':' . $display->did;
00109
00110 if ($pane) {
00111 $id .= ':' . $pane->pid;
00112 }
00113
00114 if (user_access('view pane admin links')) {
00115 $id .= ':admin';
00116 }
00117
00118 switch ($conf['granularity']) {
00119 case 'args':
00120 foreach ($args as $arg) {
00121 $id .= ':' . $arg;
00122 }
00123 break;
00124
00125 case 'context':
00126 if (!is_array($contexts)) {
00127 $contexts = array($contexts);
00128 }
00129 foreach ($contexts as $context) {
00130 if (isset($context->argument)) {
00131 $id .= ':' . $context->argument;
00132 }
00133 }
00134 }
00135 return $id;
00136 }
00137
00138 function panels_simple_cache_settings_form($conf, $display, $pid) {
00139 $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');
00140 $form['lifetime'] = array(
00141 '#title' => t('Lifetime'),
00142 '#type' => 'select',
00143 '#options' => $options,
00144 '#default_value' => $conf['lifetime'],
00145 );
00146
00147 $form['granularity'] = array(
00148 '#title' => t('Granularity'),
00149 '#type' => t('select'),
00150 '#options' => array(
00151 'args' => t('Arguments'),
00152 'context' => t('Context'),
00153 'none' => t('None'),
00154 ),
00155 '#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.'),
00156 '#default_value' => $conf['granularity'],
00157 );
00158
00159 return $form;
00160 }
00161