I have a file called api.php which is loaded using parameters, for example:
api.php?name=NAME&format=xml
which would return a xml page with some data, or
api.php?name=NAME&format=JSON would return the same data in json format.
The xml page is generated using this:
function generate_valid_xml_from_array($array, $node_block='xboxapi', $node_name='game') {
$xml = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
$xml .= '<' . $node_block . '>' . "\n";
$xml .= generate_xml_from_array($array, $node_name);
$xml .= '</' . $node_block . '>' . "\n";
return $xml;
}
$xml = generate_valid_xml_from_array($array);
header('Content-type: text/xml');
print $xml;
and the json is returned using this:
header('Content-type: application/json');
echo json_encode($data);
How would i set the returned data to be cached for 1 hour, and then updated hourly on request?
I have been scratching my head with this one for a while now