Ejemplo n.º 1
0
 public function run(WS_Environment $env)
 {
     $dsn = $this->dsn ? $this->dsn : $env->config->cache->dsn;
     if (empty($dsn)) {
         $dsn = 'dummy://';
     }
     $timeout = $this->timeout ? $this->timeout : (isset($env->config->cache->timeout) ? $env->config->cache->timeout : null);
     $env->cache = Cache::connect($dsn, $timeout);
     $tagged = !is_null($this->tagged) ? $this->tagged : (isset($env->config->cache->tagged) ? $env->config->cache->tagged : !$env->cache->is_support_nesting());
     $locked = !is_null($this->locked) ? $this->locked : (isset($env->config->cache->locked) ? $env->config->cache->locked : false);
     if ($tagged) {
         Core::load('Cache.Tagged');
         $env->cache = Cache_Tagged::Client($env->cache);
     }
     if ($locked) {
         Core::load('Cache.Locked');
         $env->cache = Cache_Locked::Client($env->cache);
     }
     $response = null;
     foreach ($this->urls as $regexp => $timeout) {
         if (preg_match($regexp, $env->request->path)) {
             if (($response = $env->cache->get('ws.middlweware.cache.pages:' . $env->request->url)) === null) {
                 $response = $this->application->run($env);
                 $env->cache->set('ws.middleware.cache.pages:' . $env->request->url, $response, $timeout);
             }
             break;
         }
     }
     return $response ? $response : $this->application->run($env);
 }