public static function load($file, $cache = 3600) { if ($cache > 0 && RUN_MODE == 'deploy') { import('system/bin/cache'); $cache_instance = CacheBackend::get_instance(); $cache_id = 'yaml_' . str_replace(array('/', '.'), '_', $file); if ($cache_instance->is_cached($cache_id)) { return $cache_instance->get($cache_id); } else { if (!is_file($file)) { $file = Package::get_file($file); if (!is_file($file)) { return array(); } } import('system/vendors/spyc/spyc'); $info = spyc_load_file($file); $cache_instance->set($cache_id, $info); return $info; } } if (!is_file($file)) { $file = Package::get_file($file); if (!is_file($file)) { return array(); } } import('system/vendors/spyc/spyc'); $info = spyc_load_file($file); return $info; }
/** * Construct cache backend * * Session backend does not use any params * * @param array $params * @return CacheBackend */ function __construct($params = null) { parent::__construct($params); if (!isset($_SESSION[$this->var_name])) { $_SESSION[$this->var_name] = array(); } // if }
/** * Constructor * * @param array $params * @return FileCacheBackend */ function __construct($params = null) { parent::__construct($params); $cache_dir = array_var($params, 'cache_dir'); if (empty($cache_dir)) { $cache_dir = ENVIRONMENT_PATH . '/cache/'; } // if $this->setCacheDir($cache_dir); clearstatcache(); }
public function __construct(array $config = null) { parent::__construct($config); $this->instance = new Memcached(); if ($config['nodes'] && is_array($config['nodes'])) { foreach ($config['nodes'] as $node) { $this->instance->addServer($node['host'], $node['port']); } } if (!$this->instance instanceof Memcached) { throw new CacheException(1006, 'memcache'); } }
public static function get_instance(array $config = null) { if (self::$object_instance instanceof CacheInterface) { return self::$object_instance; } if ($config) { foreach ($config as $key => $value) { self::$config[$key] = $value; } } self::$config['use'] = self::$config['use'] ? self::$config['use'] : ini('base/CACHE_BACKEND'); if (!self::$config['use'] || !self::is_available(self::$config['use'])) { self::$config['use'] = 'file'; } if (is_object(self::$object_instance) && self::$object_instance instanceof $cache_instance_class) { return self::$object_instance; } $ini_config = ini('runtime/cache'); if ($ini_config) { foreach ($ini_config as $key => $value) { $this->config[$key] = $value; } } if ($config) { foreach ($config as $key => $value) { self::$config[$key] = $value; } } import('system/share/cache/interface'); import('system/share/cache/' . strtolower(self::$config['use'])); $cache_instance_class = ucfirst(self::$config['use']); try { self::$object_instance = new $cache_instance_class(); if (method_exists(self::$object_instance, 'check_available')) { $code = self::$object_instance->check_available(); if ($code !== true) { import('system/share/exception/CacheException'); throw new CacheException((int) $code, self::$object_instance->error_message); } } } catch (CacheException $e) { if (RUN_MODE == 'devel') { throw new CacheException(1006, self::$config['use']); } else { self::$object_instance = new File(); } } return self::$object_instance; }
public static function init() { if (self::$inited == true) { return true; } import('system/bin/yaml'); import('system/bin/cache'); $cache_instance = CacheBackend::get_instance(array('use' => 'xcache')); $cache_id = '__BASE__CONFIG__'; if ($cache_instance->is_cached($cache_id) && RUN_MODE == 'deploy') { self::$config['base'] = $cache_instance->get($cache_id); } else { self::$config['base'] = YamlBackend::load('etc/common.yml', false); $cache_instance->set($cache_id, self::$config['base']); } self::$inited = true; }
protected function __load__cache__(array $config = null, $new = false) { if (is_object($this->cache_instance) && !$new) { return $this->cache_instance; } import('system/bin/cache'); $this->cache_instance = CacheBackend::get_instance($config); return $this->cache_instance; }
public function clear_cache() { import('system/bin/cache'); CacheBackend::get_instance()->flush(); $this->smarty->clearAllCache(); }
public static function dispatch($app, $view_action, array $params = null) { $view_action = $view_action ? $view_action : 'index'; import('system/bin/application'); import('system/bin/cache'); /* * application's url pattern mapping */ $app_map_array = YamlBackend::load('etc/conf.d/urls.yml'); if ($app_map_array['map'][$app]) { $app = $app_map_array['map'][$app]; } else { if (array_keys($app_map_array['map'], $app)) { throw new DispatchException(1011, $app . '/' . $view_action); } } /* * Cache all INSTALLED APPS urls pattern */ $cache_id = 'URLS_MAP'; $url_name_map_cache_id = 'URL_NAME_MAP'; $app_map_array_flip_cache_id = 'URL_APP_MAP_ARRAY_FLIP'; $cache_instance = CacheBackend::get_instance(); if ($cache_instance->is_cached($cache_id) && RUN_MODE == 'deploy' && false) { self::$url_patterns = $cache_instance->get($cache_id); self::$url_name_map = $cache_instance->get($url_name_map_cache_id); $app_map_array_flip = $cache_instance->get($app_map_array_flip_cache_id); } else { $installed_apps = ini('base/INSTALLED_APPS'); $app_map_array_flip = array_flip($app_map_array['map']); foreach ($installed_apps as $installed_app) { $urlpattern = YamlBackend::load(sprintf('applications/%s/urls.yml', $installed_app)); if ($app_map_array_flip[$installed_app]) { $installed_app = $app_map_array_flip[$installed_app]; } /* * The url-name map to view action * like: url name='auth_login' => auth.AuthController.login */ if ($urlpattern) { foreach ($urlpattern as $key => $value) { if ($value['name']) { self::$url_name_map[$value['name']] = $installed_app . '/' . $key; } } } self::$url_patterns[$installed_app] = $urlpattern; } $cache_instance->set($cache_id, self::$url_patterns); if (self::$url_name_map) { $cache_instance->set($url_name_map_cache_id, self::$url_name_map); } $cache_instance->set($app_map_array_flip_cache_id, $app_map_array_flip); } $app_map_name = array_key_exists($app, $app_map_array_flip) ? $app_map_array_flip[$app] : $app; $urlpattern = self::$url_patterns[$app_map_name]; try { /* * does not set the action key */ if (!$urlpattern[$view_action]['action']) { $_c = ucfirst($app) . 'Controller'; try { import(Package::get_file(sprintf('applications/%s/%s', $app, $_c))); $urlpattern[$view_action]['action'] = $_c . '.' . $view_action; } catch (DoesNotExistsException $e) { throw new DispatchException(1011, $app . '/' . $view_action); } } list($controller, $method) = explode('.', $urlpattern[$view_action]['action']); import(sprintf('applications/%s/%s', $app, $controller)); if (!is_callable(array($controller, $method))) { throw new DispatchException(1011, $app . '/' . $view_action); } /* * Set current application and action */ RuntimeConfig::set('runtime/application', $app); RuntimeConfig::set('runtime/action', $view_action); RuntimeConfig::set('runtime/view_action', $app . '/' . $view_action); BaseConfig::load_application_config($app); try { $controller = new $controller($params); RuntimeConfig::set('runtime/application_instance', $controller); /* * Re-init the plugins with the application implements */ Pluggable::init($controller); /* * Trigger the plugins in before_application_run */ Pluggable::trigger('before_application_run'); /* * Call the view-action method */ call_user_func_array(array($controller, $method), (array) $params); /* * Dependence exception */ } catch (DependenceException $e) { //pass } /* * When the DispatchException catched * Return the 404 */ } catch (DispatchException $e) { $app = new BaseApplication(); Pluggable::init($app); Pluggable::trigger('before_application_run'); $app->load('smarty')->display('404'); } }