net.i2p.router.networkdb.kademlia

## Class NegativeLookupCache

- java.lang.Object
- - net.i2p.router.networkdb.kademlia.NegativeLookupCache

-     class NegativeLookupCache
      extends Object

  Negative cache for network database lookup operations.

  Caches failed lookup attempts to prevent repeated queries to unavailable or malicious peers. Implements time-based expiration and configurable failure thresholds to balance between cache effectiveness and resource usage.

  Uses LRU eviction policy and periodic cleanup to maintain cache size. Provides DOS protection by rate-limiting repeated failed lookups for the same targets within configurable time windows.

  Thread-safe implementation with atomic counters and scheduled cleanup operations for reliable concurrent access in multi-threaded environments.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static int` | `MAX_FAILS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NegativeLookupCache(RouterContext context)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cache(Hash h)` Negative cache the hash until the next clean time.
    `void` | `clear()`
    `void` | `failPermanently(Destination dest)` Negative cache the hash until restart, but cache the destination.
    `Destination` | `getBadDest(Hash h)` Get an unsupported but cached Destination
    `boolean` | `isCached(Hash h)`
    `void` | `lookupFailed(Hash h)`
    `void` | `stop()` Stops the timer.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAX_FAILS

          static final int MAX_FAILS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NegativeLookupCache

          public NegativeLookupCache(RouterContext context)

  - ### Method Detail

    - #### cache

          public void cache(Hash h)

      Negative cache the hash until the next clean time.

    - #### clear

          public void clear()

    - #### failPermanently

          public void failPermanently(Destination dest)

      Negative cache the hash until restart, but cache the destination.

    - #### getBadDest

          public Destination getBadDest(Hash h)

      Get an unsupported but cached Destination
      Returns:
        dest or null if not cached

    - #### isCached

          public boolean isCached(Hash h)

    - #### lookupFailed

          public void lookupFailed(Hash h)

    - #### stop

          public void stop()

      Stops the timer. May not be restarted.