public function testGetters()
 {
     $cacheKey = 'cacheKey';
     $cacheFor = 100;
     $request = new CachedBatchRequest($cacheKey, $cacheFor);
     $this->assertEquals($cacheKey, $request->getCacheKey());
     $this->assertEquals($cacheFor, $request->getCacheFor());
 }
示例#2
0
 /**
  * Send multiple concurrent requests to the API.
  *
  * @param CachedBatchRequest $batchRequest
  * @return string[]
  */
 public function sendCachedBatch(CachedBatchRequest $batchRequest)
 {
     $cached = $this->memcache->get($batchRequest->getCacheKey());
     if (false !== $cached) {
         return unserialize($cached);
     }
     $responses = $this->sendBatch($batchRequest);
     $out = [];
     foreach ($responses as $response) {
         $out[] = is_object($response) ? (string) $response->getBody() : null;
     }
     $this->memcache->set($batchRequest->getCacheKey(), serialize($out), 0, $batchRequest->getCacheFor());
     return $out;
 }