<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Datastore_WinCache extends vB_Datastore { protected $store_result = false; public function resetCache() { wincache_ucache_clear(); } public function fetch($items) { if (!function_exists('wincache_ucache_get')) { throw new Exception('WinCache not installed'); } if (!sizeof($items = $this->prepare_itemarray($items))) { return; } $this->fastDSFetch($items); if (empty($items)) { return true; } $unfetched_items = array(); foreach ($items AS $item) { $this->do_fetch($item, $unfetched_items); } $this->store_result = true; if (!empty($unfetched_items)) { if (!($result = $this->do_db_fetch($this->prepare_itemlist($unfetched_items)))) { return false; } } $this->store_result = false; $this->check_options(); return true; } protected function do_fetch($title, &$unfetched_items) { $ptitle = $this->prefix . $title; if (($data = wincache_ucache_get($ptitle)) === false) { $unfetched_items[] = $title; return false; } $this->register($title, $data); return true; } protected function register($title, $data, $unserialize_detect = 2) { if ($this->store_result === true) { $this->storeWinCache($title, $data); } parent::register($title, $data, $unserialize_detect); } public function build($title = '', $data = '', $unserialize = 0, $storelocal = true) { parent::build($title, $data, $unserialize, $storelocal); $this->storeWinCache($title, $data); } public function delete($title) { parent::delete($title); $ptitle = $this->prefix . $title; wincache_ucache_delete($ptitle); } protected function storeWinCache($title, $data) { $ptitle = $this->prefix . $title; wincache_ucache_delete($ptitle); wincache_ucache_set($ptitle, $data); } } 