public function __construct($timers, $id = False) { $this->_memcached = \Core\Backend\Memcached::container()->get_backend(); if (!$id) { $id = \Core\Utils\IPv4::get(); } $this->_timers = $timers; $this->_id = $id; $this->_incr(); }
public function route($uri) { $uri = $this->_clean_uri($uri); $route = $this->_find_route($uri); try { if (!isset($route->parameters['__cache__'])) { throw new CacheNotEnabledError(); } $m = \Core\Backend\Memcached::container()->get_backend(); $m->setOption(\Memcached::OPT_COMPRESSION, False); if ($route->parameters['__cache__'] == 'on') { $key = sprintf("site:%s:uri:%s", \Core\Utils\Env::site_name(), $_SERVER['REQUEST_URI']); } if ($route->parameters['__cache__'] && ($page = $m->get($key) && count($_POST) == 0)) { trigger_error(sprintf("Cache hit but for key [%s] not used by proxy server.", $key), \E_USER_WARNING); } else { trigger_error("Cache miss.", \E_USER_WARNING); } $m_enable = True; } catch (\Core\FileNotFoundError $e) { trigger_error("Disabling route cache due to no config file.", \E_USER_WARNING); } catch (\Core\Error $e) { trigger_error("Disabling route cache due to no memcached section in config.", \E_USER_WARNING); } catch (CacheNotEnabledError $e) { } catch (\Core\Backend\MemcachedNotLoadedError $e) { } import('controllers.' . strtolower($route->class)); $class = sprintf('\\Controllers\\%s', str_replace('.', '\\', $route->class)); $controller = new $class($route->parameters); $method = $route->parameters['method']; if (!method_exists($controller, $method)) { $method = 'index'; } ob_start(); $controller->{$method}(); $page = ob_get_contents(); if ($m_enable) { $m->set($key, $page, time() + 60); } }
protected function _mc_session($ip) { import('core.session.handler'); import('core.session.remote_storage.memcached'); import('core.session.local_storage.cookie'); $sh = new Handler(); $srp = new RemoteStorage\Memcached(); $slc = new LocalStorage\Cookie(); $srp->attach_mc(\Core\Backend\Memcached::container()->get_backend()); $this->_load_config(); try { $sh->attach_remote_storage($srp)->attach_local_storage($slc)->attach_crypto_config($this->_config['crypto'])->set_remote_addr($ip)->initialize_remote_storage()->start(); return $sh; } catch (Core\Error $e) { echo "SERIOUSLY AN ERROR"; // Colossal failure. return False; } }