69 $this->_stream = $stream;
71 $this->_quotes = get_magic_quotes_runtime();
83 public function setString($nsKey, $itemKey, $string, $mode)
88 case self::MODE_WRITE:
89 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_START);
91 case self::MODE_APPEND:
92 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_END);
96 'Invalid mode [' . $mode .
'] used to set nsKey='.
97 $nsKey .
', itemKey=' . $itemKey
101 fwrite($fp, $string);
119 case self::MODE_WRITE:
120 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_START);
122 case self::MODE_APPEND:
123 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_END);
127 'Invalid mode [' . $mode .
'] used to set nsKey='.
128 $nsKey .
', itemKey=' . $itemKey
132 while (
false !== $bytes = $os->
read(8192))
149 $is->setKeyCache($this);
150 $is->setNsKey($nsKey);
151 $is->setItemKey($itemKey);
152 if (isset($writeThrough))
154 $is->setWriteThroughStream($writeThrough);
169 if ($this->
hasKey($nsKey, $itemKey))
171 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_START);
174 set_magic_quotes_runtime(0);
177 while (!feof($fp) &&
false !== $bytes = fread($fp, 8192))
183 set_magic_quotes_runtime(1);
197 if ($this->
hasKey($nsKey, $itemKey))
199 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_START);
202 set_magic_quotes_runtime(0);
204 while (!feof($fp) &&
false !== $bytes = fread($fp, 8192))
210 set_magic_quotes_runtime(1);
223 return is_file($this->_path .
'/' . $nsKey .
'/' . $itemKey);
233 if ($this->
hasKey($nsKey, $itemKey))
235 $fp = $this->
_getHandle($nsKey, $itemKey, self::POSITION_END);
237 unlink($this->_path .
'/' . $nsKey .
'/' . $itemKey);
239 unset($this->_keys[$nsKey][$itemKey]);
248 if (array_key_exists($nsKey, $this->_keys))
250 foreach ($this->_keys[$nsKey] as $itemKey=>$null)
254 rmdir($this->_path .
'/' . $nsKey);
255 unset($this->_keys[$nsKey]);
268 $cacheDir = $this->_path .
'/' . $nsKey;
269 if (!is_dir($cacheDir))
271 if (!mkdir($cacheDir))
275 $this->_keys[$nsKey] = array();
289 if (!isset($this->_keys[$nsKey]) || !array_key_exists($itemKey, $this->_keys[$nsKey]))
291 $fp = fopen($this->_path .
'/' . $nsKey .
'/' . $itemKey,
'w+b');
292 $this->_keys[$nsKey][$itemKey] = $fp;
294 if (self::POSITION_START == $position)
296 fseek($this->_keys[$nsKey][$itemKey], 0, SEEK_SET);
300 fseek($this->_keys[$nsKey][$itemKey], 0, SEEK_END);
302 return $this->_keys[$nsKey][$itemKey];
310 foreach ($this->_keys as $nsKey=>$null)