Example #1
0
 /**
  * HTTP GET request to a mediawiki API (with caching)
  * @param string $target Used in cache key creation, mostly
  * @param array $query The query parameters for the API request
  * @param int $cacheTTL Time to live for the memcached caching
  * @return null
  */
 public function httpGetCached($target, $query, $cacheTTL = 3600)
 {
     if ($this->mApiBase) {
         $url = wfAppendQuery($this->mApiBase, $query);
     } else {
         $url = $this->makeUrl($query, 'api');
     }
     if (!isset($this->mQueryCache[$url])) {
         $data = ObjectCache::getMainWANInstance()->getWithSetCallback($this->getLocalCacheKey(get_class($this), $target, md5($url)), $cacheTTL, function () use($url) {
             return ForeignAPIRepo::httpGet($url);
         });
         if (!$data) {
             return null;
         }
         if (count($this->mQueryCache) > 100) {
             // Keep the cache from growing infinitely
             $this->mQueryCache = [];
         }
         $this->mQueryCache[$url] = $data;
     }
     return $this->mQueryCache[$url];
 }