/**
  * Get from the cache
  *
  * @param string  $id
  * @param string  $group
  * @return mixed
  */
 function get($id, $group = 'transient', $force = false, &$found = null)
 {
     if ($this->_debug) {
         $time_start = Util_Debug::microtime();
     }
     $key = $this->_get_cache_key($id);
     list($fragment_group, $fragment_group_expiration, $fragment_group_global) = $this->_fragment_group($id, $group);
     $internal = isset($this->cache[$fragment_group][$key]);
     if ($internal) {
         $found = true;
         $value = $this->cache[$fragment_group][$key];
     } elseif ($this->_caching && !in_array($group, $this->nonpersistent_groups)) {
         $cache = $this->_get_cache($fragment_group_global);
         $v = $cache->get($key, $fragment_group);
         if (is_array($v) && $v['content'] != null) {
             $found = true;
             $value = $v['content'];
         } else {
             $value = false;
         }
     } else {
         $value = false;
     }
     if ($value === null) {
         $value = false;
     }
     if (is_object($value)) {
         $value = clone $value;
     }
     $this->cache[$fragment_group][$key] = $value;
     $this->cache_total++;
     if ($value !== false) {
         $cached = true;
         $this->cache_hits++;
     } else {
         $cached = false;
         $this->cache_misses++;
     }
     /**
      * Add debug info
      */
     if ($this->_debug) {
         $time = Util_Debug::microtime() - $time_start;
         $this->time_total += $time;
         if (!$group) {
             $group = 'transient';
         }
         $this->debug_info[] = array('id' => $id, 'group' => $group, 'cached' => $cached, 'internal' => $internal, 'data_size' => $value ? strlen(serialize($value)) : '', 'time' => $time);
     }
     return $value;
 }
コード例 #2
0
 /**
  * Returns debug info
  *
  * @param boolean $cache
  * @param string  $reason
  * @param boolean $status
  * @param double  $time
  * @return string
  */
 public function w3tc_footer_comment($strings)
 {
     $strings[] = sprintf(__('Page Caching using %s%s', 'w3-total-cache'), Cache::engine_name($this->_config->get_string('pgcache.engine')), $this->cache_reject_reason != '' ? sprintf(' (%s)', $this->cache_reject_reason) : '');
     if ($this->_debug) {
         $time_total = Util_Debug::microtime() - $this->_time_start;
         $engine = $this->_config->get_string('pgcache.engine');
         $strings[] = "Page cache debug info:";
         $strings[] = sprintf("%s%s", str_pad('Engine: ', 20), Cache::engine_name($engine));
         $strings[] = sprintf("%s%s", str_pad('Cache key: ', 20), $this->_page_key);
         if ($this->cache_reject_reason != '') {
             $strings[] = sprintf("%s%s", str_pad('Reject reason: ', 20), $this->cache_reject_reason);
         }
         $strings[] = sprintf("%s%.3fs", str_pad('Creation Time: ', 20), time());
         $headers = $this->_get_response_headers();
         if (count($headers)) {
             $strings[] = "Header info:";
             foreach ($headers as $header_name => $header_value) {
                 $strings[] = sprintf("%s%s", str_pad($header_name . ': ', 20), Util_Content::escape_comment($header_value));
             }
         }
     }
     return $strings;
 }