#1  
03-10-2011, 05:42 PM
admin's Avatar
admin admin is offline
Site Staff | Web Development
 
Join Date: Jul 2003
Posts: 4,309
Thanked 654 Times in 457 Posts
[NOTES]

Specify Wincache object cache in WordPress code.

From http://blogs.iis.net/ruslany/archive...cache-1-1.aspx
and mirrored at http://ruslany.net/2010/03/make-word...-wincache-1-1/

"To configure WordPress to use WinCache user cache API’s copy the following code and put it in the file named object-cache.php located at the /wp-content/ directory of your WordPress site.

Code:
<?php

/*
Name: WinCache Cache
Description: WinCache backend for the WP Object Cache.
Version: 0.1
URI: http://ruslany.net/
Author: Ruslan Yakushev

Install this file to wp-content/object-cache.php

Big thanks to Mark Jaquith (http://markjaquith.wordpress.com/)
whose apc-object-cache.php was used as a basis for this code.
*/

// gracefully revert to default cache if WinCache is not installed
if ( !extension_loaded('wincache') ||
      !function_exists('wincache_ucache_get') ||
      strcmp(ini_get('wincache.ucenabled'), "1") )  {
 include_once(ABSPATH . WPINC . '/cache.php');
} else {

function wp_cache_add($key, $data, $flag = '', $expire = 0) {
  global $wp_object_cache;
  return $wp_object_cache->add($key, $data, $flag, $expire);
}

function wp_cache_close() {
  return true;
}

function wp_cache_delete($id, $flag = '') {
  global $wp_object_cache;
  return $wp_object_cache->delete($id, $flag);
}

function wp_cache_flush() {
  global $wp_object_cache;

  return $wp_object_cache->flush();
}

function wp_cache_get($id, $flag = '') {
  global $wp_object_cache;
  return $wp_object_cache->get($id, $flag);
}

function wp_cache_init() {
  global $wp_object_cache;
  $wp_object_cache = new WP_Object_Cache();
}

function wp_cache_replace($key, $data, $flag = '', $expire = 0) {
  global $wp_object_cache;
  return $wp_object_cache->replace($key, $data, $flag, $expire);
}

function wp_cache_set($key, $data, $flag = '', $expire = 0) {
  global $wp_object_cache;
  return $wp_object_cache->set($key, $data, $flag, $expire);
}

class WP_Object_Cache {
  var $global_groups = array ('users', 'userlogins', 'usermeta');
  var $cache = array ();

  function add($id, $data, $group = 'default', $expire = 0) {
    return $this->set($id, $data, $group, $expire);
  }

  function delete($id, $group = 'default') {
    $key = $this->key($id, $group);
    $result = wincache_ucache_delete($key);
    if ( false !== $result )
      unset($this->cache[$key]);
    return $result;
  }

  function flush() {
    wincache_ucache_clear();
    return true;
  }

  function get($id, $group = 'default') {
    $key = $this->key($id, $group);
     if ( isset($this->cache[$key]) )
      $value = $this->cache[$key];
    else
      $value = wincache_ucache_get($key);
    /* echo "Cache key: $key<br/>";
    echo 'Cache value:<br/>';
    var_dump($value);
    echo '<br/>'; */
    if ( NULL === $value )
      $value = false;
    $this->cache[$key] = $value;
    return $value;
  }

  function key($key, $group) {
    global $blog_id;
    if ( empty($group) )
      $group = 'default';
    if (false !== array_search($group, $this->global_groups))
      $prefix = '';
    else
      $prefix = $blog_id . ':';
    return md5(ABSPATH . "$prefix$group:$key");
  }

  function replace($id, $data, $group = 'default', $expire = 0) {
    return $this->set($id, $data, $group, $expire);
  }

  function set($id, $data, $group = 'default', $expire = 0) {
    $key = $this->key($id, $group);
    $result = wincache_ucache_set($key, $data, $expire);
    if ( false !== $result )
      $this->cache[$key] = $data;
    return $result;
  }

  function stats() {
    $wincache_info = wincache_ucache_info();
    echo "<p>\n";
    echo "<strong>Cache Hits:</strong> {$wincache_info['total_hit_count']}<br/>\n";
    echo "<strong>Cache Misses:</strong> {$wincache_info['total_miss_count']}<br/>\n";
    echo "</p>\n";
    if ( ! empty($this->cache) ) {
      echo "<pre>\n";
      print_r($this->cache);
      echo "</pre>\n";
    }
  }

  function WP_Object_Cache() {
   // Nothing here
  }
 }
}
?>
Excellent.

- Did this site help you? Then upgrade to Premium Member and show your support!
- Also: Like Us on Facebook for special DVD/Blu-ray news and deals!
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Ads / Sponsors
 
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Helicontech suggested gzip settings [notes] admin Website and Server Troubleshooting 0 03-10-2011 05:33 PM
Project notes, VHS restores (RK@2009) admin Project Planning, Workflows 0 11-30-2009 11:52 AM
Project notes, VHS restoration (GK@2008) admin Project Planning, Workflows 2 11-29-2009 11:05 AM
Availables blogs/CMS [NOTES] admin Web Development, Design 0 08-11-2009 12:42 AM
Research for OSx86 install, Hackintosh notes admin Computers 0 08-11-2009 12:37 AM

Thread Tools



 
All times are GMT -5. The time now is 03:05 AM