5 * Provides a simple time-based caching option for panel panes.
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',
19 'granularity' => 'none',
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');
33 if ((time() - $cache->created
) > $conf['lifetime']) {
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);
49 * Clear cached content.
51 * Cache clears are always for an entire display, regardless of arguments.
53 function panels_simple_cache_clear_cache($display) {
54 $cid = 'panels_simple_cache';
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
;
60 $cid .
= ':' .
$display->did
;
62 cache_clear_all($cid, 'cache', TRUE
);
66 * Figure out an id for our cache based upon input and settings.
68 function panels_simple_cache_get_id($conf, $display, $args, $contexts, $pane) {
69 $id = 'panels_simple_cache';
71 // If the panel is stored in the database it'll have a numeric did value.
72 if (is_numeric($display->did
)) {
73 $id .
= ':' .
$display->did
;
75 // Exported panels won't have a numeric did but may have a usable cache_key.
76 elseif (!empty($display->cache_key
)) {
77 $id .
= ':' .
str_replace('panel_context:', '', $display->cache_key
);
79 // Alternatively use the css_id.
80 elseif (!empty($display->css_id
)) {
81 $id .
= ':' .
$display->css_id
;
83 // Failover to just appending the did, which may be the completely unusable
86 $id .
= ':' .
$display->did
;
90 $id .
= ':' .
$pane->pid
;
93 if (user_access('view pane admin links')) {
97 switch ($conf['granularity']) {
99 foreach ($args as
$arg) {
105 if (!is_array($contexts)) {
106 $contexts = array($contexts);
108 foreach ($contexts as
$context) {
109 if (isset($context->argument
)) {
110 $id .
= ':' .
$context->argument
;
114 if (module_exists('locale')) {
116 $id .
= ':' .
$language->language
;
119 if(!empty($pane->configuration
['use_pager']) && !empty($_GET['page'])) {
120 $id .
= ':p' .
check_plain($_GET['page']);
126 function panels_simple_cache_settings_form($conf, $display, $pid) {
127 $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');
128 $form['lifetime'] = array(
129 '#title' => t('Lifetime'),
131 '#options' => $options,
132 '#default_value' => $conf['lifetime'],
135 $form['granularity'] = array(
136 '#title' => t('Granularity'),
139 'args' => t('Arguments'),
140 'context' => t('Context'),
143 '#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.'),
144 '#default_value' => $conf['granularity'],