1<?php 2/** 3 * DokuWiki Plugin memcache (Helper Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author János Fekete <jan@fjan.eu> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12class helper_plugin_memcache extends DokuWiki_Plugin { 13 14 public function __construct() { 15 if (!defined('MEMCACHE_CHECK_KEYS')){ 16 $this->loadConfig(); 17 /* 18 NOTE: as both apc and wincache supports arrays for many functions, this class DOES NOT. 19 The variables are not checked for better performance, but checking can be enabled for debuging in which case non-string keys trigger error. 20 */ 21 define('MEMCACHE_CHECK_KEYS',(bool)$this->conf['debug_check_keys']); 22 } 23 require_once('classes/memcache_interface.loader.php'); 24 25 } 26 /** 27 * Return info about supported methods in this Helper Plugin 28 * 29 * @return array of public methods 30 */ 31 function getMethods() { 32 $result = array(); 33 $result[] = array( 34 'name' => 'key_checks_enabled', 35 'desc' => "returns MEMCACHE_CHECK_KEYS constant's value.", 36 'return' => array('enabled'=>'boolean'), 37 ); 38 $result[] = array( 39 'name' => 'driver', 40 'desc' => 'returns the backend driver as string (which is either "wincache" or "apc" currently or "fake" if neither is supported, and using filesys-caching instead.)', 41 'return' => array('driver'=>'string'), 42 ); 43 $result[] = array( 44 'name' => 'emulated', 45 'desc' => 'returns true if the driver is emulated (no performance boost)', 46 'return' => array('emulated'=>'boolean'), 47 ); 48 $result[] = array( 49 'name' => 'add', 50 'desc' => "add one entry, if it does not exists already. returns boolean success (false if key already exists or something went wrong)\n if ttl parameter is given and positive, it will set time-to-live, else it will remain until cache clear.", 51 'parameters' => array( 52 'key' => 'string', 53 'val' => 'mixed (serializable)', 54 'ttl' => 'integer', 55 ), 56 'return' => array('success'=>'boolean'), 57 ); 58 $result[] = array( 59 'name' => 'set', 60 'desc' => "set one entry: create new or overwrite old value. returns boolean success (false if something went wrong). if ttl parameter is given and positive, it will set time-to-live, else it will remain until cache clear.", 61 'parameters' => array( 62 'key' => 'string', 63 'val' => 'mixed (serializable)', 64 'ttl' => 'integer', 65 ), 66 'return' => array('success'=>'boolean'), 67 ); 68 $result[] = array( 69 'name' => 'exists', 70 'desc' => "checks if a key exists.", 71 'parameters' => array( 72 'key' => 'string', 73 ), 74 'return' => array('exists'=>'boolean'), 75 ); 76 $result[] = array( 77 'name' => 'del', 78 'desc' => "deletes data by its key.", 79 'parameters' => array( 80 'key' => 'string', 81 ), 82 'return' => array('success'=>'boolean'), 83 ); 84 $result[] = array( 85 'name' => 'get', 86 'desc' => "retrieves a value. returns retrieved value or null. \$success out-parameter can be checked to check success (you may have false, null, 0, or '' as stored value).", 87 'parameters' => array( 88 'key' => 'string', 89 'success' => 'boolean (out)', 90 ), 91 'return' => array('value'=>'mixed'), 92 ); 93 $result[] = array( 94 'name' => 'clear', 95 'desc' => "clears the entire cache. (note: server-wide, so clears cache for every code that uses the same driver). returns boolean success (which should be always true)", 96 'return' => array('success'=>'boolean'), 97 ); 98 99 return $result; 100 } 101 102 function key_checks_enabled(){ 103 return (bool) @MEMCACHE_CHECK_KEYS; 104 } 105 106 function driver(){ 107 return memcache::driver(); 108 } 109 110 function emulated(){ 111 return memcache::emulated(); 112 } 113 114 function clear(){ 115 return memcache::clear(); 116 } 117 118 function add($key,$val,$ttl = 0){ 119 return memcache::add($key,$val,$ttl); 120 } 121 122 function set($key,$val,$ttl = 0){ 123 return memcache::set($key,$val,$ttl); 124 } 125 126 function exists($key){ 127 return memcache::exists($key); 128 } 129 130 function del($key){ 131 return memcache::del($key); 132 } 133 134 function get($key,&$success = false){ 135 return memcache::get($key,$success); 136 } 137 138 139} 140 141// vim:ts=4:sw=4:et: 142