Changeset 59141 for trunk/src/wp-includes/SimplePie/src/Cache/Memcache.php
- Timestamp:
- 09/30/2024 10:48:16 PM (6 months ago)
- Location:
- trunk/src/wp-includes/SimplePie/src
- Files:
-
- 1 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Cache/Memcache.php
r47733 r59141 1 1 <?php 2 2 3 /** 3 4 * SimplePie … … 6 7 * Takes the hard work out of managing a complete RSS/Atom solution. 7 8 * 8 * Copyright (c) 2004-20 16, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors9 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors 9 10 * All rights reserved. 10 11 * … … 42 43 */ 43 44 45 namespace SimplePie\Cache; 46 47 use Memcache as NativeMemcache; 48 44 49 /** 45 50 * Caches data to memcache … … 54 59 * @subpackage Caching 55 60 * @uses Memcache 61 * @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead 56 62 */ 57 class SimplePie_Cache_Memcache implements SimplePie_Cache_Base63 class Memcache implements Base 58 64 { 59 60 61 62 63 64 65 /** 66 * Memcache instance 67 * 68 * @var Memcache 69 */ 70 protected $cache; 65 71 66 67 68 69 70 71 72 /** 73 * Options 74 * 75 * @var array 76 */ 77 protected $options; 72 78 73 74 75 76 77 78 79 /** 80 * Cache name 81 * 82 * @var string 83 */ 84 protected $name; 79 85 80 81 82 83 84 85 * @param string$type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data86 87 88 89 $this->options = array( 90 91 92 'extras' => array( 93 94 95 ),96 );97 $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));86 /** 87 * Create a new cache object 88 * 89 * @param string $location Location string (from SimplePie::$cache_location) 90 * @param string $name Unique ID for the cache 91 * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data 92 */ 93 public function __construct($location, $name, $type) 94 { 95 $this->options = [ 96 'host' => '127.0.0.1', 97 'port' => 11211, 98 'extras' => [ 99 'timeout' => 3600, // one hour 100 'prefix' => 'simplepie_', 101 ], 102 ]; 103 $this->options = array_replace_recursive($this->options, \SimplePie\Cache::parse_URL($location)); 98 104 99 105 $this->name = $this->options['extras']['prefix'] . md5("$name:$type"); 100 106 101 $this->cache = newMemcache();102 103 107 $this->cache = new NativeMemcache(); 108 $this->cache->addServer($this->options['host'], (int) $this->options['port']); 109 } 104 110 105 /** 106 * Save data to the cache 107 * 108 * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 109 * @return bool Successfulness 110 */ 111 public function save($data) 112 { 113 if ($data instanceof SimplePie) 114 { 115 $data = $data->data; 116 } 117 return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 118 } 111 /** 112 * Save data to the cache 113 * 114 * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property 115 * @return bool Successfulness 116 */ 117 public function save($data) 118 { 119 if ($data instanceof \SimplePie\SimplePie) { 120 $data = $data->data; 121 } 122 return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 123 } 119 124 120 121 122 123 124 125 126 127 125 /** 126 * Retrieve the data saved to the cache 127 * 128 * @return array Data for SimplePie::$data 129 */ 130 public function load() 131 { 132 $data = $this->cache->get($this->name); 128 133 129 if ($data !== false) 130 { 131 return unserialize($data); 132 } 133 return false; 134 } 134 if ($data !== false) { 135 return unserialize($data); 136 } 137 return false; 138 } 135 139 136 137 138 139 140 141 142 143 140 /** 141 * Retrieve the last modified time for the cache 142 * 143 * @return int Timestamp 144 */ 145 public function mtime() 146 { 147 $data = $this->cache->get($this->name); 144 148 145 if ($data !== false) 146 { 147 // essentially ignore the mtime because Memcache expires on its own 148 return time(); 149 } 149 if ($data !== false) { 150 // essentially ignore the mtime because Memcache expires on its own 151 return time(); 152 } 150 153 151 152 154 return false; 155 } 153 156 154 155 156 157 158 159 160 161 157 /** 158 * Set the last modified time to the current time 159 * 160 * @return bool Success status 161 */ 162 public function touch() 163 { 164 $data = $this->cache->get($this->name); 162 165 163 if ($data !== false) 164 { 165 return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 166 } 166 if ($data !== false) { 167 return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']); 168 } 167 169 168 169 170 return false; 171 } 170 172 171 172 173 174 175 176 177 178 179 173 /** 174 * Remove the cache 175 * 176 * @return bool Success status 177 */ 178 public function unlink() 179 { 180 return $this->cache->delete($this->name, 0); 181 } 180 182 } 183 184 class_alias('SimplePie\Cache\Memcache', 'SimplePie_Cache_Memcache');
Note: See TracChangeset
for help on using the changeset viewer.