original_string: public static function invalidate_by_event($event, array $keys) {
          $instance = cache_config::instance();
          $invalidationeventset = false;
          $factory = cache_factory::instance();
          $inuse = $factory->get_caches_in_use();
          $purgetoken = null;
          foreach ($instance->get_definitions() as $name => $definitionarr) {
              $definition = cache_definition::load($name, $definitionarr);
              if ($definition->invalidates_on_event($event)) {
                  // First up check if there is a cache loader for this definition already.
                  // If there is we need to invalidate the keys from there.
                  $definitionkey = $definition->get_component().'/'.$definition->get_area();
                  if (isset($inuse[$definitionkey])) {
                      $inuse[$definitionkey]->delete_many($keys);
                  }
  
                  // We should only log events for application and session caches.
                  // Request caches shouldn't have events as all data is lost at the end of the request.
                  // Events should only be logged once of course and likely several definitions are watching so we
                  // track its logging with $invalidationeventset.
                  $logevent = ($invalidationeventset === false && $definition->get_mode() !== cache_store::MODE_REQUEST);
  
                  if ($logevent) {
                      // Get the event invalidation cache.
                      $cache = cache::make('core', 'eventinvalidation');
                      // Get any existing invalidated keys for this cache.
                      $data = $cache->get($event);
                      if ($data === false) {
                          // There are none.
                          $data = array();
                      }
                      // Add our keys to them with the current cache timestamp.
                      if (null === $purgetoken) {
                          $purgetoken = cache::get_purge_token(true);
                      }
                      foreach ($keys as $key) {
                          $data[$key] = $purgetoken;
                      }
                      // Set that data back to the cache.
                      $cache->set($event, $data);
                      // This only needs to occur once.
                      $invalidationeventset = true;
                  }
              }
          }
      }
code: public static function invalidate_by_event($event, array $keys) {
          $instance = cache_config::instance();
          $invalidationeventset = false;
          $factory = cache_factory::instance();
          $inuse = $factory->get_caches_in_use();
          $purgetoken = null;
          foreach ($instance->get_definitions() as $name => $definitionarr) {
              $definition = cache_definition::load($name, $definitionarr);
              if ($definition->invalidates_on_event($event)) {
                  // First up check if there is a cache loader for this definition already.
                  // If there is we need to invalidate the keys from there.
                  $definitionkey = $definition->get_component().'/'.$definition->get_area();
                  if (isset($inuse[$definitionkey])) {
                      $inuse[$definitionkey]->delete_many($keys);
                  }
  
                  // We should only log events for application and session caches.
                  // Request caches shouldn't have events as all data is lost at the end of the request.
                  // Events should only be logged once of course and likely several definitions are watching so we
                  // track its logging with $invalidationeventset.
                  $logevent = ($invalidationeventset === false && $definition->get_mode() !== cache_store::MODE_REQUEST);
  
                  if ($logevent) {
                      // Get the event invalidation cache.
                      $cache = cache::make('core', 'eventinvalidation');
                      // Get any existing invalidated keys for this cache.
                      $data = $cache->get($event);
                      if ($data === false) {
                          // There are none.
                          $data = array();
                      }
                      // Add our keys to them with the current cache timestamp.
                      if (null === $purgetoken) {
                          $purgetoken = cache::get_purge_token(true);
                      }
                      foreach ($keys as $key) {
                          $data[$key] = $purgetoken;
                      }
                      // Set that data back to the cache.
                      $cache->set($event, $data);
                      // This only needs to occur once.
                      $invalidationeventset = true;
                  }
              }
          }
      }
code_tokens: public static function invalidate_by_event ( $ event , array $ keys ) { $ instance = cache_config :: instance ( ) ; $ invalidationeventset = false ; $ factory = cache_factory :: instance ( ) ; $ inuse = $ factory -> get_caches_in_use ( ) ; $ purgetoken = null ; foreach ( $ instance -> get_definitions ( ) as $ name => $ definitionarr ) { $ definition = cache_definition :: load ( $ name , $ definitionarr ) ; if ( $ definition -> invalidates_on_event ( $ event ) ) { // First up check if there is a cache loader for this definition already. // If there is we need to invalidate the keys from there. $ definitionkey = $ definition -> get_component ( ) . '/' . $ definition -> get_area ( ) ; if ( isset ( $ inuse [ $ definitionkey ] ) ) { $ inuse [ $ definitionkey ] -> delete_many ( $ keys ) ; } // We should only log events for application and session caches. // Request caches shouldn't have events as all data is lost at the end of the request. // Events should only be logged once of course and likely several definitions are watching so we // track its logging with $invalidationeventset. $ logevent = ( $ invalidationeventset === false && $ definition -> get_mode ( ) !== cache_store :: MODE_REQUEST ) ; if ( $ logevent ) { // Get the event invalidation cache. $ cache = cache :: make ( 'core' , 'eventinvalidation' ) ; // Get any existing invalidated keys for this cache. $ data = $ cache -> get ( $ event ) ; if ( $ data === false ) { // There are none. $ data = array ( ) ; } // Add our keys to them with the current cache timestamp. if ( null === $ purgetoken ) { $ purgetoken = cache :: get_purge_token ( true ) ; } foreach ( $ keys as $ key ) { $ data [ $ key ] = $ purgetoken ; } // Set that data back to the cache. $ cache -> set ( $ event , $ data ) ; // This only needs to occur once. $ invalidationeventset = true ; } } } }
docstring: Invalidates a given set of keys by means of an event.
  
  Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation
  are only supported on caches without identifiers.
  
  @param string $event
  @param array $keys
docstring_tokens: Invalidates a given set of keys by means of an event .