79 if (!extension_loaded(
'dba')) {
80 die(
'PHP is not compiled with dba support, required to use DBM style cache.');
84 if (function_exists(
'dba_handlers')) {
85 if (!in_array(
'db3', dba_handlers())) {
86 die(
'PHP is not compiled --with '.$cache_type.
' support, required to use DBM style cache.');
92 $contents = ob_get_contents();
94 if (!strstr($contents, $cache_type)) {
95 die(
'PHP is not compiled --with '.$cache_type.
' support, required to use DBM style cache.');
100 if (!file_exists($lock_filename)) {
101 if (!touch($lock_filename)) {
102 die(
'failed to create lock file: ' . $lock_filename);
107 if (!is_writeable($lock_filename)) {
108 die(
'lock file: ' . $lock_filename .
' is not writable');
110 $this->lock = fopen($lock_filename,
'w');
113 flock($this->lock, LOCK_EX);
116 if (!file_exists($dbm_filename)) {
117 if (!touch($dbm_filename)) {
118 die(
'failed to create dbm file: ' . $dbm_filename);
123 $this->dba = @dba_open($dbm_filename,
'w', $cache_type);
127 $this->dba = dba_open($dbm_filename,
'n', $cache_type);
130 die(
'failed to create dbm file: ' . $dbm_filename);
138 $this->cache_type = $cache_type;
139 $this->dbm_filename = $dbm_filename;
142 register_shutdown_function(array($this,
'__destruct'));
158 @dba_close($this->dba);
161 @flock($this->lock, LOCK_UN);
164 @fclose($this->lock);
173 dba_close($this->dba);
176 $this->dba = dba_open($this->dbm_filename,
'n', $this->cache_type);
179 die(
'failed to clear cache/recreate dbm file: ' . $this->dbm_filename);
186 register_shutdown_function(array($this,
'__destruct'));
200 $result = dba_fetch($key, $this->dba);
203 if ($result !==
false) {
204 return unserialize($result);
213 dba_insert($key, serialize($result), $this->dba);