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 _key($type) { return sprintf("site:%s:throttle:%s:%s", \Core\Utils\Env::site_name(), $this->_id, $type); }
protected function _key($sid, $tok, $field) { return sprintf('session:%s:%s:%s:%s', \Core\Utils\Env::site_name(), $sid, $tok, $field); }