Exemple #1
0
 /**
  * Gets a response from the cache decorators based on `$key`. [Request_Cache] will
  * iterate through each attached decorator searching for a hit. When a response
  * is found, if it is still fresh it will be returned.
  * 
  *     // Search for a response
  *     if (($response = Request::$cache->get('foo')) instanceof Kohana_Response)
  *     {
  *          // Return the response
  *          return $response;
  *     }
  *
  * @param   string   key of the response to fetch from cache
  * @return  boolean|Kohana_Response
  */
 public function get($key)
 {
     // If there are no decorators
     if (!$this->cache_decorators) {
         // return
         return FALSE;
     }
     // Foreach decorator
     foreach ($this->cache_decorators as $decorator) {
         try {
             // Try and load the response by key
             $cached_response = $decorator->get($key);
             // If the cache response is valid
             if ($cached_response instanceof Kohana_Response and Request_Cache::validate_get($cached_response)) {
                 // return the response
                 return $cached_response;
             }
         } catch (Exception $e) {
             // If cache exceptions should be thrown
             if (!$this->silent_cache_fail) {
                 // Throw the exception
                 throw $e;
             }
         }
     }
     // return false if no response was found
     return FALSE;
 }