/** * @param string $key The object KEY * @param int $ttl The time to live in seconds of the object. Depends on implementation. * @return object The Object */ public function get($key, $ttl = 0) { $log = LogHandler::getInstance(); if ($ttl === false) { $log->info("[Shmop Cache] Ignored {$key} because TTL=FALSE"); return null; } if (CacheContext::getInstance()->getReset()) { $log->info("[Shmop Cache] Failed to get {$key} because RESET=true"); return null; } if (CacheContext::getInstance()->getNoCache()) { $log->info("[Shmop Cache] Failed to get {$key} because NOCACHE=true"); return null; } $fileKey = $this->getKeyId($key); // Opened $shm_id = @shmop_open($fileKey, "a", 0, 0); if (!$shm_id) { $log->info("[Shmop Cache] '{$key}' not exists"); return null; } $fileAge = filemtime($this->getFTok($key)); // Check if ($ttl > 0 && intval(time() - $fileAge) > $ttl) { $log->info("[Shmop Cache] File too old. Ignoring '{$key}'"); // Close old descriptor shmop_close($shm_id); // delete old memory segment $shm_id = shmop_open($fileKey, "w", $this->getDefaultPermission(), $this->getMaxSize()); shmop_delete($shm_id); shmop_close($shm_id); return null; } $log->info("[Shmop Cache] Get '{$key}'"); $serialized = shmop_read($shm_id, 0, shmop_size($shm_id)); shmop_close($shm_id); return unserialize($serialized); }
/** * * @param string $key * @param string $str * @return bool */ public function append($key, $str) { $this->lazyLoadMemCachedServers(); $log = LogHandler::getInstance(); if (!CacheContext::getInstance()->getNoCache()) { $log->info("[Memcached] Append '{$key}' in Memcached"); return $this->_memCached->append($key, $str); } else { $log->info("[Memcached] Not Set '{$key}' because NOCACHE=true"); } return true; }
/** * @param string $key The object Key * @param object $object The object to be cached * @param int $ttl The time to live in seconds of this objects * @return bool If the object is successfully posted */ public function append($key, $content, $ttl = 0) { $log = LogHandler::getInstance(); $fileKey = $this->fixKey($key); if (!CacheContext::getInstance()->getNoCache()) { $log->info("[Filesystem cache] Append '{$key}' in FileSystem"); try { file_put_contents($fileKey, serialize($content), true); } catch (Exception $ex) { echo "<br/><b>Warning:</b> I could not write to cache on file '" . basename($key) . "'. Switching to nocache=true mode. <br/>"; } } else { $log->info("[Filesystem cache] Not Set '{$key}' because NOCACHE=true"); } }