public function get_content() { $content = $this->cache->get($this->file_path); if ($content == null) { //不在缓存里,从阿里云oss获取 $oss = new CAliyunOSS(); $content = $oss->get_object($this->file_path, $this->bucket); // save to cache. $this->cache->put($this->file_path, $content); return $content; } else { return $content; } }
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"); } }
public static function get_oss_client() { self::$_OSS_ACCESS_ID = CConfig::$oss_config['access_id']; self::$_OSS_ACCESS_KEY = CConfig::$oss_config['access_key']; self::$_OSS_ENDPOINT = CConfig::$oss_config['endpoint']; self::$_OSS_BUCKET = CConfig::$oss_config['bucket']; try { $oss_client = new OssClient(self::$_OSS_ACCESS_ID, self::$_OSS_ACCESS_KEY, self::$_OSS_ENDPOINT, false); return $oss_client; } catch (OssException $e) { printf(__FUNCTION__ . " creating OssClient instance: FAILED \n "); printf($e->getMessage() . "\n"); return NULL; } }