1 <?php
3 class gosa_cache
4 {
5 var $c_memcache = NULL;
6 var $b_connected= FALSE;
8 function __construct()
9 {
10 $this->connect();
11 }
14 function connect()
15 {
16 $this->close();
17 if(class_exists("Memcache")){
18 $this->c_memcache = new Memcache;
19 $res = $this->c_memcache->pconnect("localhost",11211);
20 if(!$res){
21 $this->b_connected = FALSE;
22 $this->c_memcache = NULL;
23 }else{
24 $this->b_connected = TRUE;
25 }
26 }
27 }
29 function close()
30 {
31 if($this->b_connected){
32 $this->c_memcache->close();
33 }
34 }
37 function save($key,$value)
38 {
39 if($this->b_connected){
40 $this->c_memcache->set($key,$value);
41 }
42 }
44 function load($key)
45 {
46 if($this->b_connected){
47 return($this->c_memcache->get($key));
48 }
49 }
51 function remove($key)
52 {
53 if($this->b_connected){
54 return($this->c_memcache->delete($key));
55 }
56 }
58 function status()
59 {
60 if($this->b_connected){
61 return($this->c_memcache->getStats());
62 }else{
63 return("");
64 }
65 }
66 }
69 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
70 ?>