Cached HTTP request.
@return stdClass|stdClass[]
199930
public function cachedRequest(string $resource, array $data = [], $cacheExpire = null)
	{
		if (!self::$cacheDir) {
			return $this->request($resource, 'GET', $data);
		}
		if ($cacheExpire === null) {
			$cacheExpire = self::$cacheExpire;
		}

		$cacheFile = self::$cacheDir
			. '/twitter.'
			. md5($resource . json_encode($data) . serialize([$this->consumer, $this->token]))
			. '.json';

		$cache = @json_decode(@file_get_contents($cacheFile)); // intentionally @
		$expiration = is_string($cacheExpire) ? strtotime($cacheExpire) - time() : $cacheExpire;
		if ($cache && @filemtime($cacheFile) + $expiration > time()) { // intentionally @
			return $cache;
		}

		try {
			$payload = $this->request($resource, 'GET', $data);
			file_put_contents($cacheFile, json_encode($payload));
			return $payload;

		} catch (Exception $e) {
			if ($cache) {
				return $cache;
			}
			throw $e;
		}
	}
22924
public function getCached()
    {
        $cached = $this->cache->get(
            $this->getCacheKey(),
            []
        );

        return $this->formatCache($cached);
    }
393061
public function cache()
    {
        $keys = [
            'enable_caching',
            'cache_duration'
        ];
        $this->CacheSettings = $this->loadModel('Wasabi/Core.CacheSettings');
        $settings = $this->CacheSettings->getKeyValues(new CacheSetting(), $keys);
        if ($this->request->is('post') && !empty($this->request->data)) {
            $settings = $this->CacheSettings->newEntity($this->request->data);
            if (!$settings->errors()) {
                if ($this->CacheSettings->saveKeyValues($settings, $keys)) {
                    $this->Flash->success(__d('wasabi_core', 'The cache settings have been updated.'));
                    $this->redirect(['action' => 'cache']);
                    return;
                } else {
                    $this->Flash->error($this->dbErrorMessage);
                }
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }
        $this->set([
            'settings' => $settings,
            'cacheDurations' => $this->CacheSettings->cacheDurations
        ]);
    }
292733
public function getAll()
    {
        $values = json_decode(file_get_contents($this->cacheFile), true);

        if( ! is_array($values)) return [];
        
        foreach ($values as $key => $value) {
            $values[$key] = unserialize($value);
        }
        return $values;
    }
218216
public function getCachedField(): array
    {
        if (empty($this->cached) || !is_array($this->cached)) {
            $this->cached = [];
        }

        return $this->cached;
    }
291680
public function getResponseHeaders() {
        $requestHeaders = [];

        if ($this->headers instanceof \ArrayAccess) {
            while ($this->headers->valid()) {
                $requestHeaders[$this->headers->key()] = $this->headers->current();
                $this->headers->next();
            }
        }

        return $requestHeaders;
    }
1138921
public function getAsPair()
    {
        $result = array();

        foreach ($this->data as $key => $options) {
            $result[$key] = $options[self::CACHE_PARAM_VALUE];
        }

        return $result;
    }
288785
protected static function getRequestInfos()
    {
        $url            = static :: getRequestUrl();
        $user_agent     = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
        $ip_address     = isset($_SERVER['REMOTE_ADDR'])     ? $_SERVER['REMOTE_ADDR']     : null;
        $hostname       = @gethostbyaddr($ip_address);
        $referer        = isset($_SERVER["HTTP_REFERER"])    ? $_SERVER["HTTP_REFERER"]    : null;
        $request_method = isset($_SERVER["REQUEST_METHOD"])  ? $_SERVER["REQUEST_METHOD"]  : null;

        return [$url, $user_agent, $ip_address, $hostname, $referer, $request_method];
    }
1024808
public static function getAllRequestHeaders() {
        static $_cached_headers = false;
        if($_cached_headers!==false) {
            return $_cached_headers;
        }
        $headers = array();
        if(function_exists('getallheaders')) {
            foreach( getallheaders() as $name => $value ) {
                $headers[strtolower($name)] = $value;
            }
        } else {
            foreach($_SERVER as $name => $value) {
                if(substr($name, 0, 5) == 'HTTP_') {
                    $headers[strtolower(str_replace(' ', '-', str_replace('_', ' ', substr($name, 5))))] = $value;
                }
            }
        }
        return $_cached_headers = $headers;
    }
344783
private function getCache()
    {
        $cachePath = $this->getCachePath();

        if (!$this->files->exists($cachePath)) {
            $this->createCache();

            $this->optimize();
        }

        return collect(json_decode($this->files->get($cachePath), true));
    }
1059546
private static function cache()
    {
        if (is_null(self::$memcached) && class_exists('Memcached')) {
            $servers = [['host' => '127.0.0.1', 'port' => 11211, 'weight' => 100]];

            self::$memcached = new Memcached();

            foreach ($servers as $server) {
                self::$memcached->addServer(
                    $server['host'], $server['port'], $server['weight']
                );
            }

            if (self::$memcached->getVersion() === false) {
                throw new \RuntimeException("Could not establish Memcached connection.");
            }
        }

        return self::$memcached;
    }
144875
public function parse()
    {
        /*
         * If the object has already been parsed in this request return the cached data.
         */
        if (array_key_exists($this->filePath, self::$cache)) {
            self::$cache[$this->filePath]['source'] = 'request-cache';
            return self::$cache[$this->filePath];
        }

        /*
         * Try to load the parsed data from the cache
         */
        $path = $this->getCacheFilePath();

        $result = [
            'filePath' => $path,
            'className' => null,
            'source' => null,
            'offset' => 0
        ];

        /*
         * There are two types of possible caching scenarios, either stored
         * in the cache itself, or stored as a cache file. In both cases,
         * make sure the cache is not stale and use it.
         */
        if (is_file($path)) {
            $cachedInfo = $this->getCachedFileInfo();
            $hasCache = $cachedInfo !== null;

            /*
             * Valid cache, return result
             */
            if ($hasCache && $cachedInfo['mtime'] == $this->object->mtime) {
                $result['className'] = $cachedInfo['className'];
                $result['source'] = 'cache';

                return self::$cache[$this->filePath] = $result;
            }

            /*
             * Cache expired, cache file not stale, refresh cache and return result
             */
            if (!$hasCache && filemtime($path) >= $this->object->mtime) {
                $className = $this->extractClassFromFile($path);
                if ($className) {
                    $result['className'] = $className;
                    $result['source'] = 'file-cache';

                    $this->storeCachedInfo($result);
                    return $result;
                }
            }
        }

        $result['className'] = $this->rebuild($path);
        $result['source'] = 'parser';

        $this->storeCachedInfo($result);
        return $result;
    }
1324398
private function getHeaders()
        {
            if(function_exists('apache_request_headers')) {
                return apache_request_headers();
            }
            $headers = array();
            $keys = preg_grep('{^HTTP_}i', array_keys($_SERVER));
            foreach($keys as $val) {
                    $key = repl(' ', '-', ucwords(Inflector::lower(repl('_', ' ', substr($val, 5)))));
                    $headers[$key] = $_SERVER[$val];
                }
            return $headers;
        }
1258981
function jsonSerialize(): \stdClass {
    return (object) [
      'name' => $this->getName(),
      'url' => ($url = $this->getUrl()) ? (string) $url : null
    ];
  }
5815
public function send()
    {
        $responses = new \StdClass();

        foreach ($this->resources as $key => $promise) {
            $response = $promise->wait();
            $responses->{$key} = $this->parse($response->getBody());
        }

        return $responses;
    }
300705
private function cachedAll() {
		if (!isset($this->{__METHOD__})) {
			$this->{__METHOD__} = array_merge($this->cachedAllGlobal(), $this->cachedAllPerStore());
		}
		return $this->{__METHOD__};
	}
370718
public static function getRequestHeaders()
    {
        if (function_exists('getallheaders')) {
            $headers = array();
            foreach (getallheaders() as $name => $value) {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('-', ' ', $name))))] = $value;
            }
            return $headers;
        }
        $headers = array();
        foreach ($_SERVER as $name => $value) {
            if (substr($name, 0, 5) == 'HTTP_') {
                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
            }
        }
        return $headers;
    }