Code

Added more msgPools
[gosa.git] / gosa-core / include / class_cache_handler.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class gosa_cache 
24 {
25   var $c_memcache = NULL;
26   var $b_connected= FALSE; 
28   function __construct()
29   {
30     $this->connect();
31   }
33   
34   function connect()
35   {
36     $this->close();
37     if(class_exists("Memcache")){
38       $this->c_memcache = new Memcache;
39       $res = $this->c_memcache->pconnect("localhost",11211);
40       if(!$res){
41         $this->b_connected = FALSE;
42         $this->c_memcache  = NULL;
43       }else{
44         $this->b_connected = TRUE;
45       }
46     }
47   }  
49   function close()
50   {
51     if($this->b_connected){
52       $this->c_memcache->close();
53     }
54   }
55   
57   function save($key,$value)
58   {
59     if($this->b_connected){
60       $this->c_memcache->set($key,$value);
61     }
62   }
64   function load($key)
65   {
66     if($this->b_connected){
67       return($this->c_memcache->get($key));
68     }
69   }
71   function remove($key)
72   {
73     if($this->b_connected){
74       return($this->c_memcache->delete($key));
75     }
76   }
78   function status()
79   {
80     if($this->b_connected){ 
81       return($this->c_memcache->getStats());
82     }else{
83       return("");
84     }
85   }
86 }
89 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
90 ?>