original_string: protected static function cache_add(context $context) {
          if (isset(self::$cache_contextsbyid[$context->id])) {
              // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow
              return;
          }
  
          if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) {
              $i = 0;
              foreach(self::$cache_contextsbyid as $ctx) {
                  $i++;
                  if ($i <= 100) {
                      // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later
                      continue;
                  }
                  if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) {
                      // we remove oldest third of the contexts to make room for more contexts
                      break;
                  }
                  unset(self::$cache_contextsbyid[$ctx->id]);
                  unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]);
                  self::$cache_count--;
              }
          }
  
          self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context;
          self::$cache_contextsbyid[$context->id] = $context;
          self::$cache_count++;
      }
code: protected static function cache_add(context $context) {
          if (isset(self::$cache_contextsbyid[$context->id])) {
              // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow
              return;
          }
  
          if (self::$cache_count >= CONTEXT_CACHE_MAX_SIZE) {
              $i = 0;
              foreach(self::$cache_contextsbyid as $ctx) {
                  $i++;
                  if ($i <= 100) {
                      // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later
                      continue;
                  }
                  if ($i > (CONTEXT_CACHE_MAX_SIZE / 3)) {
                      // we remove oldest third of the contexts to make room for more contexts
                      break;
                  }
                  unset(self::$cache_contextsbyid[$ctx->id]);
                  unset(self::$cache_contexts[$ctx->contextlevel][$ctx->instanceid]);
                  self::$cache_count--;
              }
          }
  
          self::$cache_contexts[$context->contextlevel][$context->instanceid] = $context;
          self::$cache_contextsbyid[$context->id] = $context;
          self::$cache_count++;
      }
code_tokens: protected static function cache_add ( context $ context ) { if ( isset ( self :: $ cache_contextsbyid [ $ context -> id ] ) ) { // already cached, no need to do anything - this is relatively cheap, we do all this because count() is slow return ; } if ( self :: $ cache_count >= CONTEXT_CACHE_MAX_SIZE ) { $ i = 0 ; foreach ( self :: $ cache_contextsbyid as $ ctx ) { $ i ++ ; if ( $ i <= 100 ) { // we want to keep the first contexts to be loaded on this page, hopefully they will be needed again later continue ; } if ( $ i > ( CONTEXT_CACHE_MAX_SIZE / 3 ) ) { // we remove oldest third of the contexts to make room for more contexts break ; } unset ( self :: $ cache_contextsbyid [ $ ctx -> id ] ) ; unset ( self :: $ cache_contexts [ $ ctx -> contextlevel ] [ $ ctx -> instanceid ] ) ; self :: $ cache_count -- ; } } self :: $ cache_contexts [ $ context -> contextlevel ] [ $ context -> instanceid ] = $ context ; self :: $ cache_contextsbyid [ $ context -> id ] = $ context ; self :: $ cache_count ++ ; }
docstring: Adds a context to the cache. If the cache is full, discards a batch of
  older entries.
  
  @static
  @param context $context New context to add
  @return void
docstring_tokens: Adds a context to the cache . If the cache is full discards a batch of older entries .