From a11871ec9d6d4e7ce5cb25a434ab93022f84445e Mon Sep 17 00:00:00 2001
From: Graham Taylor <gtayzlor@gmail.com>
Date: Fri, 12 Oct 2012 14:47:49 +0100
Subject: [PATCH] Issue #1811054 by tayzlor: Allows panels displays and panes
 to be cached on POST requests

---
 includes/plugins.inc     |   10 +++++++++-
 plugins/cache/simple.inc |    8 ++++++++
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/includes/plugins.inc b/includes/plugins.inc
index 9077d38..e6653bd 100644
--- a/includes/plugins.inc
+++ b/includes/plugins.inc
@@ -41,8 +41,16 @@ function panels_get_regions($layout, $display) {
  *   The cached content, or FALSE to indicate no cached content exists.
  */
 function panels_get_cached_content($display, $args, $context, $pane = NULL) {
-  // Never use cache on a POST
+  $cache = TRUE;
   if (!empty($_POST)) {
+    // Here we check if a caching plugin has implemented the ability to cache on $_POST requests.
+    // If it has we use what is selected for this display / pane, otherwise we revert back to the default
+    // of never caching on a POST request.
+    $settings = $pane ? $pane : $display;
+    $cache = isset($settings->cache['settings']['cache_post']) ? $settings->cache['settings']['cache_post'] : FALSE;
+  }
+
+  if (!$cache) {
     return FALSE;
   }
 
diff --git a/plugins/cache/simple.inc b/plugins/cache/simple.inc
index 645c36a..81ffdab 100644
--- a/plugins/cache/simple.inc
+++ b/plugins/cache/simple.inc
@@ -17,6 +17,7 @@ $plugin = array(
   'defaults' => array(
     'lifetime' => 15,
     'granularity' => 'none',
+    'cache_post' => FALSE,
   ),
 );
 
@@ -132,6 +133,13 @@ function panels_simple_cache_settings_form($conf, $display, $pid) {
     '#default_value' => $conf['lifetime'],
   );
 
+  $form['cache_post'] = array(
+    '#title' => t('Cache on POST requests'),
+    '#description' => t('By default displays / panes are only cacheable on GET requests. Enabling this means the panel content will also be cached on a POST request. Be careful with this setting if you have content that is expected to change on a POST.'),
+    '#type' => 'checkbox',
+    '#default_value' => $conf['cache_post'],
+  );
+
   $form['granularity'] = array(
     '#title' => t('Granularity'),
     '#type' => 'select',
-- 
1.7.7.5 (Apple Git-26)

