wp/wp-includes/SimplePie/Cache/Memcache.php
changeset 16 a86126ab1dd4
parent 0 d970ebf37754
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     3  * SimplePie
     3  * SimplePie
     4  *
     4  *
     5  * A PHP-Based RSS and Atom Feed Framework.
     5  * A PHP-Based RSS and Atom Feed Framework.
     6  * Takes the hard work out of managing a complete RSS/Atom solution.
     6  * Takes the hard work out of managing a complete RSS/Atom solution.
     7  *
     7  *
     8  * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
     8  * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
     9  * All rights reserved.
     9  * All rights reserved.
    10  *
    10  *
    11  * Redistribution and use in source and binary forms, with or without modification, are
    11  * Redistribution and use in source and binary forms, with or without modification, are
    12  * permitted provided that the following conditions are met:
    12  * permitted provided that the following conditions are met:
    13  *
    13  *
    31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    33  * POSSIBILITY OF SUCH DAMAGE.
    33  * POSSIBILITY OF SUCH DAMAGE.
    34  *
    34  *
    35  * @package SimplePie
    35  * @package SimplePie
    36  * @version 1.3.1
    36  * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
    37  * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
       
    38  * @author Ryan Parman
    37  * @author Ryan Parman
    39  * @author Geoffrey Sneddon
    38  * @author Sam Sneddon
    40  * @author Ryan McCue
    39  * @author Ryan McCue
    41  * @link http://simplepie.org/ SimplePie
    40  * @link http://simplepie.org/ SimplePie
    42  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
    41  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
    43  */
    42  */
    44 
    43 
    93 			'extras' => array(
    92 			'extras' => array(
    94 				'timeout' => 3600, // one hour
    93 				'timeout' => 3600, // one hour
    95 				'prefix' => 'simplepie_',
    94 				'prefix' => 'simplepie_',
    96 			),
    95 			),
    97 		);
    96 		);
    98 		$parsed = SimplePie_Cache::parse_URL($location);
    97 		$this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
    99 		$this->options['host'] = empty($parsed['host']) ? $this->options['host'] : $parsed['host'];
    98 
   100 		$this->options['port'] = empty($parsed['port']) ? $this->options['port'] : $parsed['port'];
       
   101 		$this->options['extras'] = array_merge($this->options['extras'], $parsed['extras']);
       
   102 		$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
    99 		$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
   103 
   100 
   104 		$this->cache = new Memcache();
   101 		$this->cache = new Memcache();
   105 		$this->cache->addServer($this->options['host'], (int) $this->options['port']);
   102 		$this->cache->addServer($this->options['host'], (int) $this->options['port']);
   106 	}
   103 	}
   145 	{
   142 	{
   146 		$data = $this->cache->get($this->name);
   143 		$data = $this->cache->get($this->name);
   147 
   144 
   148 		if ($data !== false)
   145 		if ($data !== false)
   149 		{
   146 		{
   150 			// essentially ignore the mtime because Memcache expires on it's own
   147 			// essentially ignore the mtime because Memcache expires on its own
   151 			return time();
   148 			return time();
   152 		}
   149 		}
   153 
   150 
   154 		return false;
   151 		return false;
   155 	}
   152 	}
   163 	{
   160 	{
   164 		$data = $this->cache->get($this->name);
   161 		$data = $this->cache->get($this->name);
   165 
   162 
   166 		if ($data !== false)
   163 		if ($data !== false)
   167 		{
   164 		{
   168 			return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
   165 			return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
   169 		}
   166 		}
   170 
   167 
   171 		return false;
   168 		return false;
   172 	}
   169 	}
   173 
   170