4 // PICKLE_PATH="/home/soltesz/research/planetlab/monitor3/pdb";
5 define("PICKLE_PATH", "pdb");
9 public function load($name)
11 if ( ! $this->exists("production." . $name) )
13 print "Exception: No such file %s" . $name . "\n";
16 $name = "production." . $name;
17 $fname = $this->__file($name);
18 $o = unserialize(file_get_contents($fname));
22 public function dump($name, $obj)
24 if ( ! file_exists(PICKLE_PATH) )
26 if ( ! mkdir(PICKLE_PATH, 0777, True) )
28 print "Exception: Unable to create directory :" . PICKLE_PATH . "\n";
31 $name = "production." . $name;
32 $fname = $this->__file($name);
34 return file_put_contents($fname, serialize($obj));
36 private function __file($name)
38 return sprintf("%s/%s.phpserial", PICKLE_PATH, $name);
41 public function exists($name)
43 return file_exists($this->__file($name));
46 public function remove($name)
48 return unlink($this->__file($name));
51 public function if_cached_else($cond, $name, $function)
53 if ( $cond and $this->exists("production.%s" % $name) )
55 $o = $this->load($name);
60 $this->dump($name, $o); # cache the object using 'name'