net.i2p.util

## Class ByteCache

- java.lang.Object
- - net.i2p.util.TryCache<ByteArray>
  - - net.i2p.util.ByteCache

-     public final class ByteCache
      extends TryCache<ByteArray>

  Cache the objects frequently used to reduce memory churn. The ByteArray should be held onto as long as the data referenced in it is needed. For small arrays where the management of valid bytes in ByteArray and prezeroing isn't required, use SimpleByteArray instead. Heap size control - survey of usage:

      +---------------------------------------------------------------------+
      |   Size    |   Max   |  MaxMem  | From                               |
      +---------------------------------------------------------------------+
      |     1K    |    32   |    32K   | tunnel TrivialPreprocessor         |
      |     1K    |   512   |   512K   | tunnel FragmentHandler             |
      |     1K    |   512   |   512K   | tunnel I2NP TunnelDataMessage      |
      |     1K    |   512   |   512K   | tunnel FragmentedMessage           |
      |   1572    |    64   |   100K   | UDP InboundMessageState            |
      |   1730    |   128   |   216K   | streaming MessageOutputStream      |
      |     4K    |    32   |    28K   | I2PTunnelRunner                    |
      |     8K    |     8   |    64K   | I2PTunnel HTTPResponseOutputStream |
      |    16K    |    16   |   256K   | I2PSnark                           |
      |    32K    |     4   |   128K   | SAM StreamSession                  |
      |    32K    |    10   |   320K   | SAM v2StreamSession                |
      |    32K    |    64   |     2M   | UDP OMS                            |
      |    32K    |   128   |     4M   | streaming MessageInputStream       |
      |    36K    |    64   |  2.25M   | streaming PacketQueue              |
      |    40K    |     8   |   320K   | DataHelper decompress              |
      |    64K    |    64   |     4M   | UDP MessageReceiver                |
      +---------------------------------------------------------------------+

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class net.i2p.util.TryCache

      `TryCache.ObjectFactory<T>`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `clearAll()` Clear everything (memory pressure)
    `static ByteCache` | `getInstance(int cacheSize, int size)`
    `void` | `release(ByteArray entry)` Put this structure back onto the available cache for reuse
    `void` | `release(ByteArray entry, boolean shouldZero)`

    - ### Methods inherited from class net.i2p.util.TryCache

      `acquire, clear, getLastUnderflowTime, shrink, size, wasUnderfilled`

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

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

- - ### Method Detail

    - #### clearAll

          public static void clearAll()

      Clear everything (memory pressure)

    - #### getInstance

          public static ByteCache getInstance(int cacheSize,
                                              int size)

    - #### release

          public final void release(ByteArray entry)

      Put this structure back onto the available cache for reuse
      Overrides:
        `release` in class `TryCache<ByteArray>`

    - #### release

          public final void release(ByteArray entry,
                                    boolean shouldZero)