• PHP reference
  • Helpers

RequestCache

class RequestCache

Quick way to load and cache a HTTP resource from a specific URL.

Example usage:

// This caches the result for that URL for one hour, // so subsequent calls to the same URL will be super fast. $url = 'https://www.includable.com/'; $content = RequestCache::getURL($url, 3600);

Methods

static string getURL(string $url, integer $ttl)

Get contents of URL, and optionally cache them for a certain time.

Parameters

  • string $url the URL for which you want to retrieve its contents
  • integer $ttl Cache TTL. Set this to a value >0 to cache the results for a certain time, or to -1 to always retrieve the last version, even if a cached version exists.

Return Value

  • string

static mixed getJSON(string $url, integer $ttl)

Get contents of URL, decode JSON, and optionally cache result for a certain time.

Parameters

  • string $url the URL for which you want to retrieve its contents
  • integer $ttl Cache TTL. Set this to a value >0 to cache the results for a certain time, or to -1 to always retrieve the last version, even if a cached version exists.

Return Value

  • mixed an object created from the JSON result