Пример #1
0
 public function get_content()
 {
     $content = $this->cache->get($this->file_path);
     if ($content == null) {
         //不在缓存里,从阿里云oss获取
         $oss = new AliyunOSS();
         $file_object = array();
         try {
             $content = $oss->get_object($this->file_path, $this->file_bucket);
             $file_object = array('status' => 200, 'content' => $content);
         } catch (OssException $e) {
             if (404 == $e->getHTTPStatus()) {
                 //resource not found
                 $content = "";
                 $file_object = array('status' => 404, 'content' => $content);
             } else {
                 $file_object = NULL;
             }
         }
         //缓存之:
         $this->cache->put($this->file_path, serialize($file_object));
         return $file_object;
     } else {
         //缓存里有
         $file_object = unserialize($content);
         return $file_object;
     }
 }
Пример #2
0
 function __construct()
 {
     if (NULL == self::$_oss_client) {
         self::$_oss_client = self::get_oss_client();
     }
     if (NULL == self::$_oss_client) {
         throw new \Exception("cannot connect to oss service");
     }
 }