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; return $wp_object_cache->set($key, $data, $flag, $expire); } class WP_Object_Cache { var $global_groups = array ('users', 'userlogins', 'usermeta'); var $cache = array(); function delete($id, $group = 'default') { $key = $this->key($id, $group); $result = @unlink($this->getkeystore($key)); if ( $result ) unset($this->cache[$key]); return $result; } function flush() { /* a bit too tricky.. will the overhead override the advantage ? */ $fileglob = glob($this->getPrefix() . '.*'); ob_start(); if(is_array($fileglob)) array_map('unlink', $fileglob); ob_get_clean(); $this->cache = array(); return true; } function get($id, $group = 'default') { $key = $this->key($id, $group); if ( isset($this->cache[$key]) ) $value = $this->cache[$key]; else $value = $this->fetch($key); $value = maybe_unserialize($value); if ( NULL === $value ) $value = false; $this->cache[$key] = $value; return $value; } function set($id, $data, $group = 'default', $expire = 0) { $key = $this->key($id, $group); if ( is_resource($data) ) return false; $data = maybe_serialize($data); $result = $this->store($key, $data, $expire); if ( $result ) $this->cache[$key] = $data; return $result; } 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() { } function fetch($key) { $ksFile = $this->getkeystore($key); clearstatcache(); if(!file_exists($ksFile)) return false; $store = unserialize(file_get_contents($ksFile)); $mtime = filemtime($ksFile); if(($mtime + $store['ttl']) > time()) return $store['data']; else return false; } function store($key,$data,$ttl) { $store = array('ttl' => $ttl, 'data' => $data); file_put_contents($this->getkeystore($key), serialize($store)); return true; } function getkeystore($key){ return $this->getPrefix() . '.' . md5($key); } function getPrefix(){ return dirname(__FILE__).'/cache/WP_Store-' . md5($_SERVER['HTTP_HOST']); } function WP_Object_Cache() { // Empty Constructor } } ?>