I need to store the content array in cache, using the provided key. Add current unix timestamp as array element ‘created’. Can someone check my code if it is correct or not!
public function writeToCache($key, $content) {
$this->cacheExtension = new DateTime;
$file = fopen($this->cacheLocation . $key . $this->cacheExtension->format("y:m:d h:i:s"), "w") or die("Unable to open file!");
fwrite($file, $content);
fclose($file);
}
I solve the problem. I was dumb!
public function writeToCache($key, $content) {
$date = new DateTime();
$date = $date->format("yy-mm-dd");
$file = fopen($this->cacheLocation . $key . "_created_" . $date, "w") or die("Unable to open file!");
fwrite($file, json_encode($content));
fclose($file);}