/**
  * Salva o cache
  * @param string $group pode ser usado __METHOD__ 
  * @param string $id um identificador para o cache, deve ser único para o mesmo $group
  * @param mixed $data o que deve ser cacheado
  * @example XCache::set(__METHOD__, $post_id, $post);
  */
 public static function set($group, $id, $data)
 {
     DCache::set($group, $id, $data);
     MCache::set($group, $id, $data);
 }
Beispiel #2
0
 static function getPart($slug)
 {
     $_part_vars = array();
     $name = null;
     for ($i = 1; $i < func_num_args(); $i++) {
         $arg = func_get_arg($i);
         if (is_array($arg)) {
             $_part_vars = $arg;
         }
         if (is_string($arg)) {
             $name = $arg;
         }
     }
     $___use_cache = isset($_part_vars['__CACHE']) && $_part_vars['__CACHE'];
     if ($___use_cache) {
         $___cache_id = serialize(func_get_args());
         if (DCache::exists(__METHOD__, $___cache_id, $_part_vars['__CACHE'])) {
             return DCache::get(__METHOD__, $___cache_id);
         }
     }
     $slug = 'parts/' . $slug;
     if ($name) {
         $templates[] = "{$slug}-{$name}.php";
     }
     $templates[] = "{$slug}.php";
     // extraindo as variaveis
     extract($_part_vars, EXTR_PREFIX_INVALID, 'var');
     global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
     if (is_array($wp_query->query_vars)) {
         extract($wp_query->query_vars, EXTR_SKIP);
     }
     ob_start();
     foreach ($templates as $filename) {
         if (file_exists(get_stylesheet_directory() . '/' . $filename)) {
             require get_stylesheet_directory() . '/' . $filename;
             break;
         } else {
             if (file_exists(get_template_directory() . '/' . $filename)) {
                 require get_template_directory() . '/' . $filename;
                 break;
             }
         }
     }
     $html = ob_get_clean();
     if ($___use_cache) {
         DCache::set(__METHOD__, $___cache_id, $html);
     }
     return $html;
 }