/**
* Add an item to the cache.
*
* @param string $id The identifier of this data.
* @param string $data The data.
* @param int $expires The timestamp the data expires.
* @param string|NULL $tag An extra tag that can be used to verify the validity of the cached data.
*/
public function addCacheItem($id, $data, $expires, $tag = NULL)
{
assert('is_string($id)');
assert('is_string($data)');
assert('is_int($expires)');
assert('is_null($tag) || is_string($tag)');
$cacheFile = $this->cacheDirectory . '/' . $id;
try {
SimpleSAML_Utilities::writeFile($cacheFile, $data);
} catch (Exception $e) {
SimpleSAML_Logger::warning($this->logLoc . 'Unable to write to cache file ' . var_export($cacheFile, TRUE));
return;
}
$expireInfo = (string) $expires;
if ($tag !== NULL) {
$expireInfo .= ':' . $tag;
}
$expireFile = $cacheFile . '.expire';
try {
SimpleSAML_Utilities::writeFile($expireFile, $expireInfo);
} catch (Exception $e) {
SimpleSAML_Logger::warning($this->logLoc . 'Unable to write expiration info to ' . var_export($expireFile, TRUE));
}
}