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;
		}
	}
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;
		}
	}
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 ; } }
Cached HTTP request.
@return stdClass|stdClass[]
Cached HTTP request .