Make WordPress Core

Ticket #27470: 27470.patch

File 27470.patch, 2.9 KB (added by Wei Feng, 11 years ago)

patch for wp-includes/class-feed.php

  • wp-includes/class-feed.php

    # HG changeset patch
    # User fengwe@luxbet.com
    # Date 1395363597 -39600
    #      Fri Mar 21 11:59:57 2014 +1100
    # Branch rss_memcache_fix
    # Node ID 48ad6ff9c075cf226dc1cefb140ce11b7c0aff50
    # Parent  e0ac7a381d1fcf239449c1ebe4770c7aedb91ac4
    added a WP_Feed_Cache_Memcache client using memcache as backend
    
    diff -r e0ac7a381d1f -r 48ad6ff9c075 wp-includes/class-feed.php
    a b  
    1111         * @access public
    1212         */
    1313        function create($location, $filename, $extension) {
    14                 return new WP_Feed_Cache_Transient($location, $filename, $extension);
     14                if (defined('MEMCACHE_SERVER')) {
     15                        return new WP_Feed_Cache_Memcache($location, $filename, $extension);
     16                } else {
     17                        return new WP_Feed_Cache_Transient($location, $filename, $extension);
     18                }
    1519        }
    1620}
    1721
     
    6468        }
    6569}
    6670
     71/**
     72 * Same as WP_Feed_Cache_Transient but use memcache as the backend
     73 * In WP_Feed_Cache, it will only be activated when MEMCACHE_SEVER is defined in wp-config
     74 */
     75class WP_Feed_Cache_Memcache {
     76        var $name;
     77        var $mod_name;
     78        var $lifetime = 43200; //Default lifetime in cache of 12 hours
     79        var $memcache = null;
     80        var $memcache_prefix = "";
     81
     82        function __construct($location, $filename, $extension) {
     83                $this->name = 'feed_' . $filename;
     84                $this->mod_name = 'feed_mod_' . $filename;
     85
     86                $lifetime = $this->lifetime;
     87                /**
     88                 * Filter the transient lifetime of the feed cache.
     89                 *
     90                 * @since 2.8.0
     91                 *
     92                 * @param int    $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours).
     93                 * @param string $filename Unique identifier for the cache object.
     94                 */
     95                $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename);
     96
     97                $this->memcache = new Memcache();
     98
     99                // MEMCACHE_SERVER is from wp-config
     100                $this->memcache->connect(MEMCACHE_SERVER, 11211);
     101                $this->memcache_prefix = DB_NAME."::";
     102        }
     103
     104        function save($data) {
     105                if ( is_a($data, 'SimplePie') )
     106                        $data = $data->data;
     107
     108                $this->memcache->set($this->memcache_prefix . $this->name, $data, $this->lifetime);
     109                $this->memcache->set($this->memcache_prefix . $this->mod_name, time(), $this->lifetime);
     110                return true;
     111        }
     112
     113        function load() {
     114                return $this->memcache->get($this->memcache_prefix . $this->name);
     115        }
     116
     117        function mtime() {
     118                return $this->memcache->get($this->memcache_prefix . $this->mod_name);
     119        }
     120
     121        function touch() {
     122                return $this->memcache->set($this->memcache_prefix . $this->mod_name, time(), $this->lifetime);
     123        }
     124
     125        function unlink() {
     126                $this->memcache->delete($this->memcache_prefix . $this->name);
     127                $this->memcache->delete($this->memcache_prefix . $this->mod_name);
     128                return true;
     129        }
     130}
     131
    67132class WP_SimplePie_File extends SimplePie_File {
    68133
    69134        function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {