require_once('ApiCache/CacheUtil.php'); require_once('ApiCache/Api.php'); // API addresses to hit $addresses = [ "https://webservices.secure-tix.com/rest/v2/getJsonEvents?userId=300&venueId=11807" , "https://webservices.secure-tix.com/rest/v2/getJsonEvents?userId=300&venueId=8513" ]; // Cache location $cacheFile = "cache/events.cache"; // Instantiate the caching utility $cacheUtil = new CacheUtil($cacheFile); if ($cacheUtil->exists() && !$cacheUtil->isExpired()) { // Cache exists and has not expired, dump the cache expiresHeader(); $cacheUtil->read(); } else { // Obtain a lock to perform the update $cacheUtil->lock(); // Recheck cache if ($cacheUtil->exists() && !$cacheUtil->isExpired()) { // Cache was updated while waiting for a lock, dump and die $cacheUtil->read(); die(); } // Combine both data sources