コード例 #1
0
 /**
  * Override the cache::construct method.
  *
  * This function gets overriden so that we can process any invalidation events if need be.
  * If the definition doesn't have any invalidation events then this occurs exactly as it would for the cache class.
  * Otherwise we look at the last invalidation time and then check the invalidation data for events that have occured
  * between then now.
  *
  * You should not call this method from your code, instead you should use the cache::make methods.
  *
  * @param cache_definition $definition
  * @param cache_store $store
  * @param cache_loader|cache_data_source $loader
  */
 public function __construct(cache_definition $definition, cache_store $store, $loader = null)
 {
     // First up copy the loadeduserid to the current user id.
     $this->currentuserid = self::$loadeduserid;
     parent::__construct($definition, $store, $loader);
     // This will trigger check tracked user. If this gets removed a call to that will need to be added here in its place.
     $this->set(self::LASTACCESS, cache::now());
     if ($definition->has_invalidation_events()) {
         $lastinvalidation = $this->get('lastsessioninvalidation');
         if ($lastinvalidation === false) {
             // This is a new session, there won't be anything to invalidate. Set the time of the last invalidation and
             // move on.
             $this->set('lastsessioninvalidation', cache::now());
             return;
         } else {
             if ($lastinvalidation == cache::now()) {
                 // We've already invalidated during this request.
                 return;
             }
         }
         // Get the event invalidation cache.
         $cache = cache::make('core', 'eventinvalidation');
         $events = $cache->get_many($definition->get_invalidation_events());
         $todelete = array();
         $purgeall = false;
         // Iterate the returned data for the events.
         foreach ($events as $event => $keys) {
             if ($keys === false) {
                 // No data to be invalidated yet.
                 continue;
             }
             // Look at each key and check the timestamp.
             foreach ($keys as $key => $timestamp) {
                 // If the timestamp of the event is more than or equal to the last invalidation (happened between the last
                 // invalidation and now)then we need to invaliate the key.
                 if ($timestamp >= $lastinvalidation) {
                     if ($key === 'purged') {
                         $purgeall = true;
                         break;
                     } else {
                         $todelete[] = $key;
                     }
                 }
             }
         }
         if ($purgeall) {
             $this->purge();
         } else {
             if (!empty($todelete)) {
                 $todelete = array_unique($todelete);
                 $this->delete_many($todelete);
             }
         }
         // Set the time of the last invalidation.
         $this->set('lastsessioninvalidation', cache::now());
     }
 }
コード例 #2
0
ファイル: cache.php プロジェクト: kevinlovesing/dokuwiki
 /**
  *
  * @param string $id page id
  * @param string $file source file for cache
  * @param string $mode input mode
  */
 public function __construct($id, $file, $mode)
 {
     if ($id) {
         $this->page = $id;
     }
     $this->file = $file;
     $this->mode = $mode;
     parent::__construct($file . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.' . $mode);
 }
コード例 #3
0
ファイル: loaders.php プロジェクト: Burick/moodle
 /**
  * Override the cache::construct method.
  *
  * This function gets overriden so that we can process any invalidation events if need be.
  * If the definition doesn't have any invalidation events then this occurs exactly as it would for the cache class.
  * Otherwise we look at the last invalidation time and then check the invalidation data for events that have occured
  * between then now.
  *
  * You should not call this method from your code, instead you should use the cache::make methods.
  *
  * @param cache_definition $definition
  * @param cache_store $store
  * @param cache_loader|cache_data_source $loader
  * @return void
  */
 public function __construct(cache_definition $definition, cache_store $store, $loader = null)
 {
     parent::__construct($definition, $store, $loader);
     if ($definition->has_invalidation_events()) {
         $lastinvalidation = $this->get('lastsessioninvalidation');
         if ($lastinvalidation === false) {
             // This is a new session, there won't be anything to invalidate. Set the time of the last invalidation and
             // move on.
             $this->set('lastsessioninvalidation', cache::now());
             return;
         } else {
             if ($lastinvalidation == cache::now()) {
                 // We've already invalidated during this request.
                 return;
             }
         }
         // Get the event invalidation cache.
         $cache = cache::make('core', 'eventinvalidation');
         $events = $cache->get_many($definition->get_invalidation_events());
         $todelete = array();
         // Iterate the returned data for the events.
         foreach ($events as $event => $keys) {
             if ($keys === false) {
                 // No data to be invalidated yet.
                 continue;
             }
             // Look at each key and check the timestamp.
             foreach ($keys as $key => $timestamp) {
                 // If the timestamp of the event is more than or equal to the last invalidation (happened between the last
                 // invalidation and now)then we need to invaliate the key.
                 if ($timestamp >= $lastinvalidation) {
                     $todelete[] = $key;
                 }
             }
         }
         if (!empty($todelete)) {
             $todelete = array_unique($todelete);
             $this->delete_many($todelete);
         }
         // Set the time of the last invalidation.
         $this->set('lastsessioninvalidation', cache::now());
     }
 }
コード例 #4
0
ファイル: memcache.php プロジェクト: joyerma/yongzhuo
 public function __construct($config)
 {
     $this->config_data = $config;
     parent::__construct($config);
     $this->config($config);
 }
コード例 #5
0
ファイル: class.cache.php プロジェクト: umonkey/molinos-cms
 public function __construct()
 {
     $this->host = new Memcache();
     $this->host->pconnect(defined('MEMCACHE_HOST') ? MEMCACHE_HOST : 'localhost');
     parent::__construct();
 }