targets = new MapCacheLRU( self::TARGET_MAX_NUM ); } /** * Add a key to the lookup and the key is used to resolve cache target * * @param int $key */ public function add( $key ) { if ( count( $this->lookups ) < self::TARGET_MAX_NUM && !$this->targets->get( $key ) ) { $this->lookups[$key] = true; } } /** * Get the cache target based on the key * * @param int $key * @return mixed|null */ public function get( $key ) { $target = $this->targets->get( $key ); if ( $target ) { return $target; } if ( isset( $this->lookups[ $key ] ) ) { // Resolve the lookup batch and store results in the cache $targets = $this->resolve( array_keys( $this->lookups ) ); foreach ( $targets as $id => $val ) { $this->targets->set( $id, $val ); } $this->lookups = []; $target = $this->targets->get( $key ); if ( $target ) { return $target; } } return null; } /** * Clear everything in local cache */ public function clearAll() { $this->targets->clear(); $this->lookups = []; } }