Ejemplo n.º 1
0
 /**
  * @return DCache 
  */
 public static function cache()
 {
     // change the cache based on the config
     if (!self::$_cache) {
         $type = 'dummy';
         $cfg = Get::cfg('cache', false);
         if (!empty($cfg['type'])) {
             $type = $cfg['type'];
         }
         switch ($type) {
             case "apc":
                 if (!extension_loaded('apc')) {
                     self::$_cache = new DApcCache();
                     self::$_cache->init();
                 } else {
                     Log::add('APC functionality was not available on the server.');
                     self::$_cache = new DDummyCache();
                     self::$_cache->init();
                 }
                 break;
             case "file":
                 Log::add('File functionality was not available on the server.');
                 self::$_cache = new DFileCache();
                 self::$_cache->init();
                 break;
             case "memcache":
                 if (class_exists('Memcache')) {
                     self::$_cache = new DMemcache();
                     self::$_cache->init();
                 } else {
                     Log::add('Memcache functionality was not available on the server.');
                     self::$_cache = new DDummyCache();
                     self::$_cache->init();
                 }
                 break;
             case "dummy":
             default:
                 self::$_cache = new DDummyCache();
                 self::$_cache->init();
         }
     }
     return self::$_cache;
 }
Ejemplo n.º 2
0
 /**
  * Deleta o valor cacheado
  * @param string $group
  * @param string $id
  */
 public static function delete($group, $id)
 {
     DCache::delete($group, $id);
     MCache::delete($group, $id);
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * Initialize the caching mechanism
  */
 public function init()
 {
     parent::init();
 }