// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
// SPDX-License-Identifier: BSD-3-Clause
namespace SimplePie\Cache;
* Caches data to the filesystem
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
class File implements Base
* @see SimplePie::$cache_location
* Create a new cache object
* @param string $location Location string (from SimplePie::$cache_location)
* @param string $name Unique ID for the cache
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
public function __construct(string $location, string $name, $type)
$this->location = $location;
$this->extension = $type;
$this->name = "$this->location/$this->filename.$this->extension";
* @param array<mixed>|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
public function save($data)
if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location)) {
if ($data instanceof \SimplePie\SimplePie) {
$data = serialize($data);
return (bool) file_put_contents($this->name, $data);
* Retrieve the data saved to the cache
* @return array<mixed>|false Data for SimplePie::$data
if (file_exists($this->name) && is_readable($this->name)) {
return unserialize((string) file_get_contents($this->name));
* Retrieve the last modified time for the cache
* @return int|false Timestamp
return @filemtime($this->name);
* Set the last modified time to the current time
* @return bool Success status
return @touch($this->name);
* @return bool Success status
if (file_exists($this->name)) {
return unlink($this->name);
class_alias('SimplePie\Cache\File', 'SimplePie_Cache_File');