The following code fetches trending topics from Twitter's API using a WOEID. It caches the response, loading from this cache the next time if its relatively fresh (generated within the last 15 minutes) to avoid returning a Rate limit exceeded message from Twitter.A 'force-refresh' flag can be passed to skip the cache.Please could someone have a look at the code and suggest ways it can be improved?<?php   use Abraham\TwitterOAuth\TwitterOAuth;$cache_file = '/home/domstapleton/public_html/home/profiles/default/cache/twitter-trends-' . $_GET['location-code'] . '.data';if (file_exists($cache_file) && !$_GET['force-refresh']) {    $data = unserialize(file_get_contents($cache_file));    if (($data['timestamp'] > time() - 15 * 60)) {        $trends = $data['trends'];        echo $trends;        exit;    }}if (!$trends) {    require '/home/domstapleton/lib/twitteroauth-master/autoload.php';    $consumer_key = 'REDACTED';    $consumer_secret = 'REDACTED';    $access_token = 'REDACTED';    $access_token_secret = 'REDACTED';    $connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);    $trends = $connection->get('trends/place', array('id' => $_GET['location-code']));    if (strpos($trends, 'Rate limit exceeded') !== false) {        if (file_exists($cache_file)) {            $data = unserialize(file_get_contents($cache_file));            $trends = $data['trends'];            echo $trends;        }    } else {        $data = array('trends' => json_encode($trends), 'timestamp' => time());        file_put_contents($cache_file, serialize($data));        echo json_encode($trends);    }}
Script that retrieves trending topics from Twitter
php;performance;api;cache;twitter