[wp-trac] [WordPress Trac] #2753: Use shared memory caching facilities

WordPress Trac wp-trac at lists.automattic.com
Tue May 30 12:35:17 GMT 2006


#2753: Use shared memory caching facilities
--------------------------+-------------------------------------------------
       Id:  2753          |      Status:  new                     
Component:  Optimization  |    Modified:  Tue May 30 12:35:17 2006
 Severity:  enhancement   |   Milestone:                          
 Priority:  normal        |     Version:  2.1                     
    Owner:  anonymous     |    Reporter:  dammit                  
--------------------------+-------------------------------------------------
 {{{
 Index: wp-includes/cache.php
 ===================================================================
 --- wp-includes/cache.php       (revision 3809)
 +++ wp-includes/cache.php       (working copy)
 @@ -31,8 +31,13 @@

  function wp_cache_init() {
         global $wp_object_cache;
 -
 -       $wp_object_cache = new WP_Object_Cache();
 +       if (defined('DISABLE_CACHE') or !defined('ENABLE_CACHE')) {
 +               $wp_object_cache = new WP_Object_Cache_Void();
 +       } elseif (function_exists('apc_store')) {
 +               $wp_object_cache = new WP_Object_Cache_APC();
 +       } else {
 +               $wp_object_cache = new WP_Object_Cache();
 +       }
  }

  function wp_cache_replace($key, $data, $flag = '', $expire = 0) {
 @@ -417,4 +422,56 @@
                 $this->blog_id = md5($blog_id);
         }
  }
 +
 +/**
 + * Base class for shared-memory enabled caches, like APC, Turck, etc
 + */
 +class WP_Object_Cache_Void {
 +       /* May be reused by children */
 +       function add($id, $data, $group='default', $expire=0) {
 +               if (empty($group))
 +                       $group = 'default';
 +               if ($this->get($id, $group))
 +                       return false;
 +               return $this->set($id, $data, $group, $expire);
 +       }
 +       /* May be reused */
 +       function replace($id, $data, $group = 'default', $expire = 0) {
 +               if (empty ($group))
 +                       $group = 'default';
 +
 +               if (false === $this->get($id, $group))
 +                       return false;
 +
 +               return $this->set($id, $data, $group, $expire);
 +       }
 +
 +       /* Just a common useful function :) */
 +       function getKey($id,$group) {
 +               global $blog_id;
 +               return "{$blog_id}:{$id}:{$group}";
 +       }
 +
 +       function save() { return true; }
 +       function delete($id, $group = 'default', $force = false) { return
 true; }
 +       function flush() { return true; }
 +       function get($id, $group = 'default') { return false; }
 +       function set($id, $data, $group = 'default', $expire = 0) { return
 true;}
 +}
 +
 +class WP_Object_Cache_APC extends WP_Object_Cache_Void {
 +       function get($id,$group='default') {
 +               if (empty ($group)) $group = 'default';
 +               return apc_fetch($this->getKey($id,$group));
 +       }
 +       function set($id,$data,$group='default',$expire=0) {
 +               if (empty ($group)) $group = 'default';
 +               return apc_store($this->getkey($id,$group),$data,$expire);
 +       }
 +       function delete($id,$group='default', $forse = false) {
 +               if (empty ($group)) $group = 'default';
 +               return apc_delete($this->getkey($id,$group));
 +       }
 +}
 +
  ?>
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/2753>
WordPress Trac <http://wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list