示例#1
0
 function get($path, array $query = [])
 {
     $tmp = FileSystem::join(static::API_BASE_URI, $path);
     \ksort($query);
     $http_build_query = \http_build_query($query);
     $url = "{$tmp}?{$http_build_query}";
     $response = $this->containerd->get($url);
     if ($response) {
         return $response;
     }
     $response = parent::get($path, $query);
     if ($response->isSuccess()) {
         $this->containerd->set($url, $response);
     }
     return $response;
 }
示例#2
0
 function set($key, $value, $expiration = 0)
 {
     if (\is_null($expiration)) {
         throw new \Exception();
     }
     if (!($expiration === 0 || 60 * 60 * 24 * 30 < $expiration)) {
         $expiration += \time();
     }
     $container = new Container();
     $container->key = $key;
     $container->value = $value;
     $container->expiration = $expiration;
     $md5 = \md5($key);
     $sha1 = \sha1($key);
     $basename = "{$md5}.{$sha1}.txt";
     $path_segments = [$this->hierarchical_part, \substr($md5, 0, 2), \substr($sha1, 0, 2), $basename];
     $filename = FileSystem::join($path_segments);
     $flags = FileSystem::MAKE_PARENT_DIRECTORY | FileSystem::SERIALIZE;
     return FileSystem::file_put_contents($filename, $container, $flags);
 }