Example #1
0
 /**
  * Wraps display in a cacheable block.
  *
  * @param array MUST contain at least the basic display params
  * @param array of extra keys to be used for cache keying
  */
 function display_with_cache($params, $keys = array())
 {
     global $Blog, $Timer, $debug, $admin_url, $Session;
     $this->init_display($params);
     // Display the debug conatainers when $debug = 2 OR when it is turned on from evo menu under "Blog" -> "Show/Hide containers"
     $display_containers = $Session->get('display_containers_' . $Blog->ID) == 1 || $debug == 2;
     if (!$Blog->get_setting('cache_enabled_widgets') || !$this->disp_params['allow_blockcache'] || $this->get_cache_status() == 'disallowed') {
         // NO CACHING - We do NOT want caching for this collection or for this specific widget:
         if ($display_containers) {
             // DEBUG:
             echo '<div class="dev-blocks dev-blocks--widget"><div class="dev-blocks-name" title="' . ($Blog->get_setting('cache_enabled_widgets') ? 'Widget params have BlockCache turned off' : 'Collection params have BlockCache turned off') . '">' . '<span class="dev-blocks-action"><a href="' . $admin_url . '?ctrl=widgets&amp;action=edit&amp;wi_ID=' . $this->ID . '">Edit</a></span>' . 'Widget: <b>' . $this->get_name() . '</b> - Cache OFF <i class="fa fa-info">?</i></div>' . "\n";
         }
         $this->display($params);
         if ($display_containers) {
             // DEBUG:
             echo "</div>\n";
         }
     } else {
         // Instantiate BlockCache:
         $Timer->resume('BlockCache');
         // Extend cache keys:
         $keys += $this->get_cache_keys();
         $this->BlockCache = new BlockCache('widget', $keys);
         $content = $this->BlockCache->check();
         $Timer->pause('BlockCache');
         if ($content !== false) {
             // cache hit, let's display:
             if ($display_containers) {
                 // DEBUG:
                 echo '<div class="dev-blocks dev-blocks--widget dev-blocks--widget--incache"><div class="dev-blocks-name" title="Cache key = ' . $this->BlockCache->serialized_keys . '">' . '<span class="dev-blocks-action"><a href="' . $admin_url . '?ctrl=widgets&amp;action=edit&amp;wi_ID=' . $this->ID . '">Edit</a></span>' . 'Widget: <b>' . $this->get_name() . '</b> - FROM cache <i class="fa fa-info">?</i></div>' . "\n";
             }
             echo $content;
             if ($display_containers) {
                 // DEBUG:
                 echo "</div>\n";
             }
         } else {
             // Cache miss, we have to generate:
             if ($display_containers) {
                 // DEBUG:
                 echo '<div class="dev-blocks dev-blocks--widget dev-blocks--widget--notincache"><div class="dev-blocks-name" title="Cache key = ' . $this->BlockCache->serialized_keys . '">' . '<span class="dev-blocks-action"><a href="' . $admin_url . '?ctrl=widgets&amp;action=edit&amp;wi_ID=' . $this->ID . '">Edit</a></span>' . 'Widget: <b>' . $this->get_name() . '</b> - NOT in cache <i class="fa fa-info">?</i></div>' . "\n";
             }
             $this->BlockCache->start_collect();
             $this->display($params);
             // Save collected cached data if needed:
             $this->BlockCache->end_collect();
             if ($display_containers) {
                 // DEBUG:
                 echo "</div>\n";
             }
         }
     }
 }
Example #2
0
 /**
  * Wraps display in a cacheable block.
  *
  * @param array MUST contain at least the basic display params
  * @param array of extra keys to be used for cache keying
  */
 function display_with_cache($params, $keys = array())
 {
     global $Blog, $Timer, $debug, $admin_url;
     $this->init_display($params);
     if (!$Blog->get_setting('cache_enabled_widgets') || !$this->disp_params['allow_blockcache']) {
         // NO CACHING - We do NOT want caching for this collection or for this specific widget:
         if ($debug == 2) {
             // DEBUG:
             echo '<div class="debug_widget"><div class="debug_widget_name" title="' . ($Blog->get_setting('cache_enabled_widgets') ? 'Widget params have BlockCache turned off' : 'Collection params have BlockCache turned off') . '"><span class="debug_container_action"><a href="' . $admin_url . '?ctrl=widgets&amp;action=edit&amp;wi_ID=' . $this->ID . '">Edit</a></span>CACHE OFF: ' . $this->get_name() . '</div><div class="$wi_class$">' . "\n";
         }
         $this->display($params);
         if ($debug == 2) {
             // DEBUG:
             echo "</div></div>\n";
         }
     } else {
         // Instantiate BlockCache:
         $Timer->resume('BlockCache');
         // Extend cache keys:
         $keys += $this->get_cache_keys();
         $this->BlockCache = new BlockCache('widget', $keys);
         $content = $this->BlockCache->check();
         $Timer->pause('BlockCache');
         if ($content !== false) {
             // cache hit, let's display:
             if ($debug == 2) {
                 // DEBUG:
                 echo '<div class="debug_widget widget_in_cache"><div class="debug_widget_name" title="' . $this->BlockCache->serialized_keys . '"><span class="debug_container_action"><a href="' . $admin_url . '?ctrl=widgets&amp;action=edit&amp;wi_ID=' . $this->ID . '">Edit</a></span>FROM CACHE: ' . $this->get_name() . '</div><div class="$wi_class$">' . "\n";
             }
             echo $content;
             if ($debug == 2) {
                 // DEBUG:
                 echo "</div></div>\n";
             }
         } else {
             // Cache miss, we have to generate:
             if ($debug == 2) {
                 // DEBUG:
                 echo '<div class="debug_widget widget_not_in_cache"><div class="debug_widget_name" title="' . $this->BlockCache->serialized_keys . '"><span class="debug_container_action"><a href="' . $admin_url . '?ctrl=widgets&amp;action=edit&amp;wi_ID=' . $this->ID . '">Edit</a></span>NOT IN CACHE: ' . $this->get_name() . '</div><div class="$wi_class$">' . "\n";
             }
             $this->BlockCache->start_collect();
             $this->display($params);
             // Save collected cached data if needed:
             $this->BlockCache->end_collect();
             if ($debug == 2) {
                 // DEBUG:
                 echo "</div></div>\n";
             }
         }
     }
 }