4 # TODO: clean up this aweful hack.
5 system("/usr/share/monitor-server/phpconfig.py > /var/www/cgi-bin/monitor/monitorconfig.php");
6 include 'monitorconfig.php';
7 define("PICKLE_PATH", MONITOR_DATA_ROOT);
11 public function load($name)
13 if ( ! $this->exists("production." . $name) )
15 print "Exception: No such file %s" . $name . "\n";
18 $name = "production." . $name;
19 $fname = $this->__file($name);
20 $o = unserialize(file_get_contents($fname));
24 public function dump($name, $obj)
26 if ( ! file_exists(PICKLE_PATH) )
28 if ( ! mkdir(PICKLE_PATH, 0777, True) )
30 print "Exception: Unable to create directory :" . PICKLE_PATH . "\n";
33 $name = "production." . $name;
34 $fname = $this->__file($name);
36 return file_put_contents($fname, serialize($obj));
38 private function __file($name)
40 return sprintf("%s/%s.phpserial", PICKLE_PATH, $name);
43 public function exists($name)
45 return file_exists($this->__file($name));
48 public function remove($name)
50 return unlink($this->__file($name));
53 public function if_cached_else($cond, $name, $function)
55 if ( $cond and $this->exists("production.%s" % $name) )
57 $o = $this->load($name);
62 $this->dump($name, $o); # cache the object using 'name'