From 10dc1e2cb4c4940981a3abd776350dc07f92fc3e Mon Sep 17 00:00:00 2001 From: filip Date: Fri, 3 Aug 2018 16:37:28 +0200 Subject: upgrade SimplePie from 1.3.1 to 1.5.2 as a part of a #mga23215 bugfix --- lib/simplepie/library/SimplePie/Cache/Memcache.php | 180 +++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 lib/simplepie/library/SimplePie/Cache/Memcache.php (limited to 'lib/simplepie/library/SimplePie/Cache/Memcache.php') diff --git a/lib/simplepie/library/SimplePie/Cache/Memcache.php b/lib/simplepie/library/SimplePie/Cache/Memcache.php new file mode 100644 index 000000000..5190eef93 --- /dev/null +++ b/lib/simplepie/library/SimplePie/Cache/Memcache.php @@ -0,0 +1,180 @@ +options = array( + 'host' => '127.0.0.1', + 'port' => 11211, + 'extras' => array( + 'timeout' => 3600, // one hour + 'prefix' => 'simplepie_', + ), + ); + $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location)); + + $this->name = $this->options['extras']['prefix'] . md5("$name:$type"); + + $this->cache = new Memcache(); + $this->cache->addServer($this->options['host'], (int) $this->options['port']); + } + + /** + * Save data to the cache + * + * @param array|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 ($data instanceof SimplePie) + { + $data = $data->data; + } + return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); + } + + /** + * Retrieve the data saved to the cache + * + * @return array Data for SimplePie::$data + */ + public function load() + { + $data = $this->cache->get($this->name); + + if ($data !== false) + { + return unserialize($data); + } + return false; + } + + /** + * Retrieve the last modified time for the cache + * + * @return int Timestamp + */ + public function mtime() + { + $data = $this->cache->get($this->name); + + if ($data !== false) + { + // essentially ignore the mtime because Memcache expires on its own + return time(); + } + + return false; + } + + /** + * Set the last modified time to the current time + * + * @return bool Success status + */ + public function touch() + { + $data = $this->cache->get($this->name); + + if ($data !== false) + { + return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); + } + + return false; + } + + /** + * Remove the cache + * + * @return bool Success status + */ + public function unlink() + { + return $this->cache->delete($this->name, 0); + } +} -- cgit v1.2.1