Exemplo n.º 1
0
 /**
  * Returns the page item cache.
  *
  * @return array
  */
 public function get_page_item_cache()
 {
     $data = array();
     if ($this->_cache_enabled()) {
         foreach (self::$_cache->getIdsMatchingTags(array($this->_get_cache_internal_id())) as $id) {
             if (preg_match('|' . self::CACHE_TAG_PREFIX . "(\\d+)_.*|", $id, $page)) {
                 $data[$page[1]] = self::$_cache->load($this->_get_cache_id($page[1]));
             }
         }
     }
     return $data;
 }
Exemplo n.º 2
0
 /**
  * Loads the configured driver and validates it.
  *
  * @param   array|string  custom configuration or config group name
  * @return  void
  */
 public function __construct($config = FALSE)
 {
     if (is_string($config)) {
         $name = $config;
         // Test the config group name
         if (($config = Kohana::config('cache.' . $config)) === NULL) {
             throw new Kohana_Exception('cache.undefined_group', $name);
         }
     }
     if (is_array($config)) {
         // Append the default configuration options
         $config += Kohana::config('cache.default');
     } else {
         // Load the default group
         $config = Kohana::config('cache.default');
     }
     // Cache the config in the object
     $this->config = $config;
     // Set driver name
     $driver = 'Cache_' . ucfirst($this->config['driver']) . '_Driver';
     // Load the driver
     if (!Kohana::auto_load($driver)) {
         throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this));
     }
     // Initialize the driver
     $this->driver = new $driver($this->config['params']);
     // Validate the driver
     if (!$this->driver instanceof Cache_Driver) {
         throw new Kohana_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Cache_Driver');
     }
     Kohana::log('debug', 'Cache Library initialized');
     if (self::$loaded !== TRUE) {
         $this->config['requests'] = (int) $this->config['requests'];
         if ($this->config['requests'] > 0 and mt_rand(1, $this->config['requests']) === 1) {
             // Do garbage collection
             $this->driver->delete_expired();
             Kohana::log('debug', 'Cache: Expired caches deleted.');
         }
         // Cache has been loaded once
         self::$loaded = TRUE;
     }
 }
Exemplo n.º 3
0
 function __construct()
 {
     E_FW::load_File('cache_Core');
     $this->_cache = Cache_Core::getInstance(E_FW::get_Config('CACHE'));
 }
Exemplo n.º 4
0
 /**
  * Set a cache item by key. Tags may also be added and a custom lifetime
  * can be set. Non-string data is automatically serialized.
  *
  * @param   string   $key
  * @param   mixed    $data
  * @param   array    $tags      use NULL
  * @param   integer  $lifetime  number of seconds until the cache expires
  * @return  boolean
  */
 public function set($key, $data, $tags = NULL, $lifetime = NULL)
 {
     Cache::$queries['sets'][] = $key;
     return parent::set($key, $data, $tags, $lifetime);
 }
Exemplo n.º 5
0
 /**
  * 组件初始化
  */
 protected static function initialize()
 {
     if (self::$initilize === FALSE) {
         self::$config = Kohana::config('cache');
         self::$initilize = TRUE;
     }
 }