46 $this->_currentObject->detach();
48 $obj = serialize($this->_currentObject);
49 if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.
'.cache',$obj,NULL,$this->_cacheTime)) {
50 if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.
'.cache',$obj,NULL,$this->_cacheTime)) {
52 throw new Exception(
'Failed to store cell '.$cellID.
' in MemCache');
55 $this->_currentObjectID = $this->_currentObject = null;
68 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
71 $this->_cellCache[$pCoord] =
true;
73 $this->_currentObjectID = $pCoord;
74 $this->_currentObject = $cell;
89 if (parent::isDataSet($pCoord)) {
90 if ($this->_currentObjectID == $pCoord) {
94 $success = $this->_memcache->get($this->_cachePrefix.$pCoord.
'.cache');
95 if ($success ===
false) {
98 throw new Exception(
'Cell entry '.$cellID.
' no longer exists in MemCache');
114 if ($pCoord === $this->_currentObjectID) {
120 if (parent::isDataSet($pCoord)) {
121 $obj = $this->_memcache->get($this->_cachePrefix.$pCoord.
'.cache');
122 if ($obj ===
false) {
125 throw new Exception(
'Cell entry '.$cellID.
' no longer exists in MemCache');
133 $this->_currentObjectID = $pCoord;
134 $this->_currentObject = unserialize($obj);
136 $this->_currentObject->attach($this->_parent);
151 $this->_memcache->delete($this->_cachePrefix.$pCoord.
'.cache');
167 $newCachePrefix = substr(md5($baseUnique),0,8).
'.';
169 foreach($cacheList as $cellID) {
170 if ($cellID != $this->_currentObjectID) {
171 $obj = $this->_memcache->get($this->_cachePrefix.$cellID.
'.cache');
172 if ($obj ===
false) {
175 throw new Exception(
'Cell entry '.$cellID.
' no longer exists in MemCache');
177 if (!$this->_memcache->add($newCachePrefix.$cellID.
'.cache',$obj,NULL,$this->_cacheTime)) {
179 throw new Exception(
'Failed to store cell '.$cellID.
' in MemCache');
183 $this->_cachePrefix = $newCachePrefix;
188 if(!is_null($this->_currentObject)) {
189 $this->_currentObject->detach();
190 $this->_currentObject = $this->_currentObjectID = null;
196 $this->_cellCache = array();
199 $this->_parent = null;
204 $memcacheServer = (isset($arguments[
'memcacheServer'])) ? $arguments[
'memcacheServer'] :
'localhost';
205 $memcachePort = (isset($arguments[
'memcachePort'])) ? $arguments[
'memcachePort'] : 11211;
206 $cacheTime = (isset($arguments[
'cacheTime'])) ? $arguments[
'cacheTime'] : 600;
208 if (is_null($this->_cachePrefix)) {
210 $this->_cachePrefix = substr(md5($baseUnique),0,8).
'.';
213 $this->_memcache =
new Memcache();
214 if (!$this->_memcache->addServer($memcacheServer, $memcachePort,
false, 50, 5, 5,
true, array($this,
'failureCallback'))) {
215 throw new Exception(
'Could not connect to MemCache server at '.$memcacheServer.
':'.$memcachePort);
217 $this->_cacheTime = $cacheTime;
225 throw new Exception(
'memcache '.$host.
':'.$port.
' failed');
231 foreach($cacheList as $cellID) {
232 $this->_memcache->delete($this->_cachePrefix.$cellID.
'.cache');