public function testSet()
 {
     $this->tearDown();
     // remove dir
     $requests = ['anime' => '+1 week', 'categorylist' => '+6 month', 'hotanime' => '+1 day', 'main' => '+1 day', 'baz' => '+1 day'];
     foreach ($requests as $request => $expires) {
         $this->cache->set($request, 'foo', 'bar');
         $this->assertEquals(strtotime($expires), filemtime($this->filename));
         $this->assertEquals('bar', $this->cache->get('foo'));
     }
 }
示例#2
0
 /**
  * Get data
  *
  * @param string $request
  * @param array $params
  * @param boolean $force
  *
  * @return \Symfony\Component\DomCrawler\Crawler
  */
 public function get($request, array $params = [], $force = false)
 {
     $path = $this->api_prefix . '&request=' . $request . ($params ? '&' . http_build_query($params) : '');
     // try get response from cache
     if ($force || !$this->cache instanceof CacheResponse || !($response = $this->cache->get($path))) {
         $response = $this->client->get($path)->setHeader('User-Agent', $this->app_code)->send();
         if ($response->isError()) {
             throw new \RuntimeException("Failed execute request '{$request}' to the server '" . $this->getApiHost() . "'");
         }
         $response = gzdecode($response->getBody(true));
         // cache response
         if ($this->cache instanceof CacheResponse) {
             $this->cache->set($request, $path, $response);
         }
     }
     return new Crawler($response);
 }