install()); } */ define("INSTALLED", true); function wp_cache_add($key, $data, $flag = '', $expire = 0) { return wp_cache_set($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) { return wp_cache_set($key, $data, $flag, $expire); } function wp_cache_set($key, $data, $flag = '', $expire = 0) { global $wp_object_cache; $data = unserialize(serialize($data)); return $wp_object_cache->set($key, $data, $flag, $expire); } class WP_Object_Cache { var $global_groups = array ('users', 'userlogins', 'usermeta'); var $cache = array(); var $table; function delete($id, $group = 'default') { global $wpdb; $key = $this->key($id, $group); $query = "DELETE * FROM {$this->table} WHERE `key`='$key'"; $wpdb->query($query); unset($this->cache[$key]); return true; } function flush() { global $wpdb; $query = "DELETE * FROM {$this->table}"; $wpdb->query($query); return true; } function get($id, $group = 'default') { global $wpdb; $key = $this->key($id, $group); if ( isset($this->cache[$key]) ) $value = $this->cache[$key]; else { $query = "SELECT `value` FROM {$this->table} WHERE `key`='$id'"; $value = $wpdb->get_var($query); } $value = base64_decode(unserialize($value)); print_r($value); if ( NULL === $value ) $value = false; $this->cache[$key] = $value; return $value; } function set($id, $data, $group = 'default', $expire = 0) { global $wpdb; $key = $this->key($id, $group); if ( is_resource($data) ) return false; $data = base64_encode(serialize($data)); $query = "INSERT INTO {$this->table} (`key`,`value`) VALUES ('$id','$data') ON DUPLICATE KEY UPDATE value='$data';"; $wpdb->query($query); $this->cache[$key] = $data; return $true; } 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 stats() { /* // Note that this is the total XCache stats, not just WP but also any other apps using XCache var storage $xcache_info = xcache_info(XC_TYPE_VAR, 0); echo "
\n";
echo "Cache Hits: {$xcache_info['hits']}
\n\r";
echo "Cache Misses: {$xcache_info['misses']}
\r\n";
echo "
\n\r"; print_r($this->cache); echo "\n\r"; } */ } function WP_Object_Cache() { global $wpdb; $this->table = $wpdb->prefix . "nst_mysql_cache"; if(INSTALLED!=true) { self::install(); } } function install() { global $wpdb; $sql= "CREATE TABLE IF NOT EXISTS {$this->table} ( `key` VARCHAR(500) NOT NULL, `value` VARCHAR(500) DEFAULT NULL, PRIMARY KEY(`key`) ) ENGINE=MEMORY PACK_KEYS=1;"; //require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); //dbDelta($sql); $wpdb->query($sql); return "The NeoSmart MySQL-based caching extension to the WordPress object-cache has been successfully installed."; } } ?>