Edit File by line
/home/barbar84/public_h.../wp-inclu.../SimplePi.../Cache
File: Redis.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* SimplePie Redis Cache Extension
[3] Fix | Delete
*
[4] Fix | Delete
* @package SimplePie
[5] Fix | Delete
* @author Jan Kozak <galvani78@gmail.com>
[6] Fix | Delete
* @link http://galvani.cz/
[7] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[8] Fix | Delete
* @version 0.2.9
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Caches data to redis
[14] Fix | Delete
*
[15] Fix | Delete
* Registered for URLs with the "redis" protocol
[16] Fix | Delete
*
[17] Fix | Delete
* For example, `redis://localhost:6379/?timeout=3600&prefix=sp_&dbIndex=0` will
[18] Fix | Delete
* connect to redis on `localhost` on port 6379. All tables will be
[19] Fix | Delete
* prefixed with `simple_primary-` and data will expire after 3600 seconds
[20] Fix | Delete
*
[21] Fix | Delete
* @package SimplePie
[22] Fix | Delete
* @subpackage Caching
[23] Fix | Delete
* @uses Redis
[24] Fix | Delete
*/
[25] Fix | Delete
class SimplePie_Cache_Redis implements SimplePie_Cache_Base {
[26] Fix | Delete
/**
[27] Fix | Delete
* Redis instance
[28] Fix | Delete
*
[29] Fix | Delete
* @var \Redis
[30] Fix | Delete
*/
[31] Fix | Delete
protected $cache;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Options
[35] Fix | Delete
*
[36] Fix | Delete
* @var array
[37] Fix | Delete
*/
[38] Fix | Delete
protected $options;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Cache name
[42] Fix | Delete
*
[43] Fix | Delete
* @var string
[44] Fix | Delete
*/
[45] Fix | Delete
protected $name;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Cache Data
[49] Fix | Delete
*
[50] Fix | Delete
* @var type
[51] Fix | Delete
*/
[52] Fix | Delete
protected $data;
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Create a new cache object
[56] Fix | Delete
*
[57] Fix | Delete
* @param string $location Location string (from SimplePie::$cache_location)
[58] Fix | Delete
* @param string $name Unique ID for the cache
[59] Fix | Delete
* @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
[60] Fix | Delete
*/
[61] Fix | Delete
public function __construct($location, $name, $options = null) {
[62] Fix | Delete
//$this->cache = \flow\simple\cache\Redis::getRedisClientInstance();
[63] Fix | Delete
$parsed = SimplePie_Cache::parse_URL($location);
[64] Fix | Delete
$redis = new Redis();
[65] Fix | Delete
$redis->connect($parsed['host'], $parsed['port']);
[66] Fix | Delete
if (isset($parsed['pass'])) {
[67] Fix | Delete
$redis->auth($parsed['pass']);
[68] Fix | Delete
}
[69] Fix | Delete
if (isset($parsed['path'])) {
[70] Fix | Delete
$redis->select((int)substr($parsed['path'], 1));
[71] Fix | Delete
}
[72] Fix | Delete
$this->cache = $redis;
[73] Fix | Delete
[74] Fix | Delete
if (!is_null($options) && is_array($options)) {
[75] Fix | Delete
$this->options = $options;
[76] Fix | Delete
} else {
[77] Fix | Delete
$this->options = array (
[78] Fix | Delete
'prefix' => 'rss:simple_primary:',
[79] Fix | Delete
'expire' => 0,
[80] Fix | Delete
);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
$this->name = $this->options['prefix'] . $name;
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* @param \Redis $cache
[88] Fix | Delete
*/
[89] Fix | Delete
public function setRedisClient(\Redis $cache) {
[90] Fix | Delete
$this->cache = $cache;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Save data to the cache
[95] Fix | Delete
*
[96] Fix | Delete
* @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
[97] Fix | Delete
* @return bool Successfulness
[98] Fix | Delete
*/
[99] Fix | Delete
public function save($data) {
[100] Fix | Delete
if ($data instanceof SimplePie) {
[101] Fix | Delete
$data = $data->data;
[102] Fix | Delete
}
[103] Fix | Delete
$response = $this->cache->set($this->name, serialize($data));
[104] Fix | Delete
if ($this->options['expire']) {
[105] Fix | Delete
$this->cache->expire($this->name, $this->options['expire']);
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
return $response;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Retrieve the data saved to the cache
[113] Fix | Delete
*
[114] Fix | Delete
* @return array Data for SimplePie::$data
[115] Fix | Delete
*/
[116] Fix | Delete
public function load() {
[117] Fix | Delete
$data = $this->cache->get($this->name);
[118] Fix | Delete
[119] Fix | Delete
if ($data !== false) {
[120] Fix | Delete
return unserialize($data);
[121] Fix | Delete
}
[122] Fix | Delete
return false;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Retrieve the last modified time for the cache
[127] Fix | Delete
*
[128] Fix | Delete
* @return int Timestamp
[129] Fix | Delete
*/
[130] Fix | Delete
public function mtime() {
[131] Fix | Delete
[132] Fix | Delete
$data = $this->cache->get($this->name);
[133] Fix | Delete
[134] Fix | Delete
if ($data !== false) {
[135] Fix | Delete
return time();
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
return false;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Set the last modified time to the current time
[143] Fix | Delete
*
[144] Fix | Delete
* @return bool Success status
[145] Fix | Delete
*/
[146] Fix | Delete
public function touch() {
[147] Fix | Delete
[148] Fix | Delete
$data = $this->cache->get($this->name);
[149] Fix | Delete
[150] Fix | Delete
if ($data !== false) {
[151] Fix | Delete
$return = $this->cache->set($this->name, $data);
[152] Fix | Delete
if ($this->options['expire']) {
[153] Fix | Delete
return $this->cache->expire($this->name, $this->ttl);
[154] Fix | Delete
}
[155] Fix | Delete
return $return;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
return false;
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Remove the cache
[163] Fix | Delete
*
[164] Fix | Delete
* @return bool Success status
[165] Fix | Delete
*/
[166] Fix | Delete
public function unlink() {
[167] Fix | Delete
return $this->cache->set($this->name, null);
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function