Beispiel #1
0
 /**
  * @return boolean
  */
 public function delete_tags()
 {
     $args = func_get_args();
     $tags = Core::normalize_args($args);
     $res = true;
     foreach ($tags as $t) {
         $tag_key = Cache_Tagged::option('tag_prefix') . $t;
         $keys = $this->backend->get($tag_key);
         if (is_array($keys)) {
             foreach ($keys as $key) {
                 $res && $this->backend->delete($key);
             }
         }
         $res = $res && $this->backend->delete($tag_key);
     }
     return $res;
 }
Beispiel #2
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);
 }