Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a WP_Feed_Cache_Memcache client using memcache as backend #74

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 66 additions & 1 deletion wp-includes/class-feed.php
Expand Up @@ -11,7 +11,11 @@ class WP_Feed_Cache extends SimplePie_Cache {
* @access public
*/
function create($location, $filename, $extension) {
return new WP_Feed_Cache_Transient($location, $filename, $extension);
if (defined('MEMCACHE_SERVER')) {
return new WP_Feed_Cache_Memcache($location, $filename, $extension);
} else {
return new WP_Feed_Cache_Transient($location, $filename, $extension);
}
}
}

Expand Down Expand Up @@ -64,6 +68,67 @@ function unlink() {
}
}

/**
* Same as WP_Feed_Cache_Transient but use memcache as the backend
* In WP_Feed_Cache, it will only be activated when MEMCACHE_SEVER is defined in wp-config
*/
class WP_Feed_Cache_Memcache {
var $name;
var $mod_name;
var $lifetime = 43200; //Default lifetime in cache of 12 hours
var $memcache = null;
var $memcache_prefix = "";

function __construct($location, $filename, $extension) {
$this->name = 'feed_' . $filename;
$this->mod_name = 'feed_mod_' . $filename;

$lifetime = $this->lifetime;
/**
* Filter the transient lifetime of the feed cache.
*
* @since 2.8.0
*
* @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
* @param string $filename Unique identifier for the cache object.
*/
$this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename);

$this->memcache = new Memcache();

// MEMCACHE_SERVER is from wp-config
$this->memcache->connect(MEMCACHE_SERVER, 11211);
$this->memcache_prefix = DB_NAME."::";
}

function save($data) {
if ( is_a($data, 'SimplePie') )
$data = $data->data;

$this->memcache->set($this->memcache_prefix . $this->name, $data, $this->lifetime);
$this->memcache->set($this->memcache_prefix . $this->mod_name, time(), $this->lifetime);
return true;
}

function load() {
return $this->memcache->get($this->memcache_prefix . $this->name);
}

function mtime() {
return $this->memcache->get($this->memcache_prefix . $this->mod_name);
}

function touch() {
return $this->memcache->set($this->memcache_prefix . $this->mod_name, time(), $this->lifetime);
}

function unlink() {
$this->memcache->delete($this->memcache_prefix . $this->name);
$this->memcache->delete($this->memcache_prefix . $this->mod_name);
return true;
}
}

class WP_SimplePie_File extends SimplePie_File {

function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
Expand Down