Edit File by line
/home/barbar84/public_h.../wp-inclu.../SimplePi.../Cache
File: Memcache.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* SimplePie
[2] Fix | Delete
*
[3] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[4] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[5] Fix | Delete
*
[6] Fix | Delete
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[7] Fix | Delete
* All rights reserved.
[8] Fix | Delete
*
[9] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[10] Fix | Delete
* permitted provided that the following conditions are met:
[11] Fix | Delete
*
[12] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[13] Fix | Delete
* conditions and the following disclaimer.
[14] Fix | Delete
*
[15] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[16] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[17] Fix | Delete
* provided with the distribution.
[18] Fix | Delete
*
[19] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[20] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[21] Fix | Delete
* written permission.
[22] Fix | Delete
*
[23] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[24] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[25] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[26] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[27] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[28] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[29] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[30] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[31] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[32] Fix | Delete
*
[33] Fix | Delete
* @package SimplePie
[34] Fix | Delete
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
[35] Fix | Delete
* @author Ryan Parman
[36] Fix | Delete
* @author Sam Sneddon
[37] Fix | Delete
* @author Ryan McCue
[38] Fix | Delete
* @link http://simplepie.org/ SimplePie
[39] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[40] Fix | Delete
*/
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Caches data to memcache
[44] Fix | Delete
*
[45] Fix | Delete
* Registered for URLs with the "memcache" protocol
[46] Fix | Delete
*
[47] Fix | Delete
* For example, `memcache://localhost:11211/?timeout=3600&prefix=sp_` will
[48] Fix | Delete
* connect to memcache on `localhost` on port 11211. All tables will be
[49] Fix | Delete
* prefixed with `sp_` and data will expire after 3600 seconds
[50] Fix | Delete
*
[51] Fix | Delete
* @package SimplePie
[52] Fix | Delete
* @subpackage Caching
[53] Fix | Delete
* @uses Memcache
[54] Fix | Delete
*/
[55] Fix | Delete
class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
[56] Fix | Delete
{
[57] Fix | Delete
/**
[58] Fix | Delete
* Memcache instance
[59] Fix | Delete
*
[60] Fix | Delete
* @var Memcache
[61] Fix | Delete
*/
[62] Fix | Delete
protected $cache;
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Options
[66] Fix | Delete
*
[67] Fix | Delete
* @var array
[68] Fix | Delete
*/
[69] Fix | Delete
protected $options;
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Cache name
[73] Fix | Delete
*
[74] Fix | Delete
* @var string
[75] Fix | Delete
*/
[76] Fix | Delete
protected $name;
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Create a new cache object
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $location Location string (from SimplePie::$cache_location)
[82] Fix | Delete
* @param string $name Unique ID for the cache
[83] Fix | Delete
* @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
[84] Fix | Delete
*/
[85] Fix | Delete
public function __construct($location, $name, $type)
[86] Fix | Delete
{
[87] Fix | Delete
$this->options = array(
[88] Fix | Delete
'host' => '127.0.0.1',
[89] Fix | Delete
'port' => 11211,
[90] Fix | Delete
'extras' => array(
[91] Fix | Delete
'timeout' => 3600, // one hour
[92] Fix | Delete
'prefix' => 'simplepie_',
[93] Fix | Delete
),
[94] Fix | Delete
);
[95] Fix | Delete
$this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
[96] Fix | Delete
[97] Fix | Delete
$this->name = $this->options['extras']['prefix'] . md5("$name:$type");
[98] Fix | Delete
[99] Fix | Delete
$this->cache = new Memcache();
[100] Fix | Delete
$this->cache->addServer($this->options['host'], (int) $this->options['port']);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Save data to the cache
[105] Fix | Delete
*
[106] Fix | Delete
* @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
[107] Fix | Delete
* @return bool Successfulness
[108] Fix | Delete
*/
[109] Fix | Delete
public function save($data)
[110] Fix | Delete
{
[111] Fix | Delete
if ($data instanceof SimplePie)
[112] Fix | Delete
{
[113] Fix | Delete
$data = $data->data;
[114] Fix | Delete
}
[115] Fix | Delete
return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Retrieve the data saved to the cache
[120] Fix | Delete
*
[121] Fix | Delete
* @return array Data for SimplePie::$data
[122] Fix | Delete
*/
[123] Fix | Delete
public function load()
[124] Fix | Delete
{
[125] Fix | Delete
$data = $this->cache->get($this->name);
[126] Fix | Delete
[127] Fix | Delete
if ($data !== false)
[128] Fix | Delete
{
[129] Fix | Delete
return unserialize($data);
[130] Fix | Delete
}
[131] Fix | Delete
return false;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Retrieve the last modified time for the cache
[136] Fix | Delete
*
[137] Fix | Delete
* @return int Timestamp
[138] Fix | Delete
*/
[139] Fix | Delete
public function mtime()
[140] Fix | Delete
{
[141] Fix | Delete
$data = $this->cache->get($this->name);
[142] Fix | Delete
[143] Fix | Delete
if ($data !== false)
[144] Fix | Delete
{
[145] Fix | Delete
// essentially ignore the mtime because Memcache expires on its own
[146] Fix | Delete
return time();
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
return false;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Set the last modified time to the current time
[154] Fix | Delete
*
[155] Fix | Delete
* @return bool Success status
[156] Fix | Delete
*/
[157] Fix | Delete
public function touch()
[158] Fix | Delete
{
[159] Fix | Delete
$data = $this->cache->get($this->name);
[160] Fix | Delete
[161] Fix | Delete
if ($data !== false)
[162] Fix | Delete
{
[163] Fix | Delete
return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
return false;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Remove the cache
[171] Fix | Delete
*
[172] Fix | Delete
* @return bool Success status
[173] Fix | Delete
*/
[174] Fix | Delete
public function unlink()
[175] Fix | Delete
{
[176] Fix | Delete
return $this->cache->delete($this->name, 0);
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function