Puts data into the cache.
string $id The cache id.:
string $data The cache entry/data.:
bool|int $lifeTime The lifetime. If != false, sets a specific lifetime for this: cache entry (null => infinite lifeTime).
boolean TRUE if the entry was successfully stored in the cache, FALSE otherwise.
Overrides CacheProvider::doSave
protected function doSave($id, $data, $lifeTime = 0) {
if ($lifeTime > 0) {
$lifeTime = time() + $lifeTime;
}
if (is_object($data) && !method_exists($data, '__set_state')) {
throw new \InvalidArgumentException("Invalid argument given, PhpFileCache only allows objects that implement __set_state() " . "and fully support var_export(). You can use the FilesystemCache to save arbitrary object " . "graphs using serialize()/deserialize().");
}
$filename = $this
->getFilename($id);
$filepath = pathinfo($filename, PATHINFO_DIRNAME);
if (!is_dir($filepath)) {
mkdir($filepath, 0777, true);
}
$value = array(
'lifetime' => $lifeTime,
'data' => $data,
);
$value = var_export($value, true);
$code = sprintf('<?php return %s;', $value);
return file_put_contents($filename, $code);
}