Exemple #1
0
 /**
  * @return APF_Cache_Factory
  */
 public static function &get_instance()
 {
     if (!self::$instance) {
         self::$instance = new MPF_Cache_Factory();
     }
     return self::$instance;
 }
Exemple #2
0
 private function set_views($idorip, $inc = 1, $time = 0)
 {
     $cache = MPF_Cache_Factory::get_instance()->get_memcache();
     if (!cache) {
         return false;
     }
     $views = $cache->get($idorip);
     if ($time) {
         $views['t'] = $views['t'] - $time;
     }
     $views['c'] = $views['c'] + $inc;
     $cache->set($idorip, $views, 0, 172800);
     /*if($time)
     			return $views[$idorip]=array('t'=>time()-$time,'c'=>1+$inc); //更新计时和计数
     		return $views[$idorip]=array('t'=>time(),'c'=>1+$inc); //更新计数*/
 }
Exemple #3
0
 public function get_inline_styles()
 {
     $url = $this->get_boundable_styles_url();
     $key = "css-" . md5($url);
     mpf_require_class('MPF_Cache_Factory');
     $mem = MPF_Cache_Factory::get_instance()->get_memcache();
     $css = $mem->get($key);
     if ($css) {
         return $css;
     }
     mpf_require_class('MPF_Http_Client_Factory');
     $c = MPF_Http_Client_Factory::get_instance()->get_curl();
     $c->set_url($url);
     $c->execute();
     $css = $c->get_response_text();
     $mem->set($key, $css, 0, 0);
     return $css;
 }
Exemple #4
0
 /**
  * 删除单行缓存
  */
 protected function cache_delete()
 {
     MPF::get_instance()->debug("delete row cache");
     $cache = MPF_Cache_Factory::get_instance()->get_memcache();
     $cache->delete($cache->get_obj_key(get_called_class(), $this->get_primary_key()));
 }
Exemple #5
0
 function url2hash($type, $file, $ext, $redisurl, $onlyhash = false)
 {
     $mpf = MPF::get_instance();
     $request = $mpf->get_request();
     $response = $mpf->get_response();
     $type_single = self::DEFAULT_RESOURCE_TYPE_SINGLE;
     $type_boundable = self::DEFAULT_RESOURCE_TYPE_BOUNDABLE;
     if ($this->is_use_redis()) {
         mpf_require_class('MPF_Cache_Factory');
         $objRedis = MPF_Cache_Factory::get_instance()->get_redis('redis');
         $strContentHash = '';
         if ($type == $type_boundable) {
             $res = $this->fetch_boundable_resources($file, $ext, TRUE);
             if (!$res) {
                 $new_file = $this->try_new_file($file);
                 if ($new_file) {
                     //301
                     $url = "{$new_file}.{$ext}";
                     $response->redirect($url, true);
                 } else {
                     //404
                     $response->set_header("HTTP/1.1", "404 Not Found", "404");
                     return;
                 }
             }
             //if(true===ANJUKE_PHP_IN_GA){
             ob_start();
             $response->add_header('ori_url', $redisurl . '|' . date('Y-m-d H:i:s'));
             $hashversion = $mpf->get_config('hash_url_version', 'resource');
             echo '/*' . $hashversion . '*/';
             $this->passthru_boundable_resources();
             $res = ob_get_contents();
             ob_clean();
             $strContentHash = md5($res);
             $objRedis->setex('url_' . $redisurl, 233280000, $strContentHash);
             $objRedis->setex('hash_' . $strContentHash, 233280000, $redisurl);
             if (!$onlyhash) {
                 echo $res;
             }
             /*}else{
                   $this->passthru_boundable_resources();
               }*/
         } elseif ($type == $type_single) {
             ob_start();
             $response->add_header('ori_url', $redisurl . '|' . date('Y-m-d H:i:s'));
             $hashversion = $mpf->get_config('hash_url_version', 'resource');
             echo '/*' . $hashversion . '*/';
             if (!$this->include_resource_file("{$file}.{$ext}")) {
                 trigger_error("Unable to include resource \"{$file}.{$ext}\"", E_USER_WARNING);
             }
             $res = ob_get_contents();
             ob_clean();
             $strContentHash = md5($res);
             $objRedis->setex('url_' . $redisurl, 233280000, $strContentHash);
             $objRedis->setex('hash_' . $strContentHash, 233280000, $redisurl);
             if (!$onlyhash) {
                 echo $res;
             }
         }
         return $strContentHash;
     } else {
         if ($type == $type_boundable) {
             $res = $this->fetch_boundable_resources($file, $ext, TRUE);
             if (!$res) {
                 $new_file = $this->try_new_file($file);
                 if ($new_file) {
                     //301
                     $url = "{$new_file}.{$ext}";
                     $response->redirect($url, true);
                 } else {
                     //404
                     $response->set_header("HTTP/1.1", "404 Not Found", "404");
                     return;
                 }
             }
             $this->passthru_boundable_resources();
         } elseif ($type == $type_single) {
             if (!$this->include_resource_file("{$file}.{$ext}")) {
                 trigger_error("Unable to include resource \"{$file}.{$ext}\"", E_USER_WARNING);
             }
         }
     }
 }
Exemple #6
0
 protected function get_cache()
 {
     return MPF_Cache_Factory::get_instance()->get_memcache();
 }
Exemple #7
0
 public function get_memcache_keys()
 {
     mpf_require_class("MPF_Cache_Factory");
     $keys = MPF_Cache_Factory::get_instance()->get_memcache()->get_read_keys();
     return $keys ? $keys : array();
 }