org.firebirdsql.gds.ng.wire

## Class InlineBlobCache

- java.lang.Object
- - org.firebirdsql.gds.ng.wire.InlineBlobCache

All Implemented Interfaces:
  DatabaseListener, TransactionListener

    public final class InlineBlobCache
    extends java.lang.Object
    implements DatabaseListener, TransactionListener

Cache for inline blobs of a single attachment.

Since:
  5.0.8
Author:
  Mark Rotteveel

### Constructor Summary

Constructors
Constructor and Description
`InlineBlobCache(FbDatabase database)` Creates an inline blob cache with the `maxBlobCacheSize` configured for `database`.

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `add(FbTransaction transaction, InlineBlob blob)` Adds an inline blob to the cache for the transaction and blob id.
`void` `detached(FbDatabase database)` Called when the `database` connection has been detached
`java.util.Optional<InlineBlob>` `getAndRemove(FbTransaction transaction, long blobId)` Gets an inline blob for the transaction and blob id and removes it from the cache.
`int` `maxSize()`
`int` `size()`
`void` `transactionStateChanged(FbTransaction transaction, TransactionState newState, TransactionState previousState)` Signals that the transaction state changed.

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

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

### Methods inherited from interface org.firebirdsql.gds.ng.listeners.DatabaseListener

`detaching, warningReceived`

### Constructor Detail

#### InlineBlobCache

    public InlineBlobCache(FbDatabase database)

Creates an inline blob cache with the `maxBlobCacheSize` configured for `database`.

Parameters:
  `database` - database instance

### Method Detail

#### maxSize

    public int maxSize()

Returns:
  the maximum cache size, `-1` if the cache is disabled

#### size

    public int size()

Returns:
  the current cache size

#### getAndRemove

    public java.util.Optional<InlineBlob> getAndRemove(FbTransaction transaction,
                                                       long blobId)

Gets an inline blob for the transaction and blob id and removes it from the cache.

Parameters:
  `transaction` - transaction
  `blobId` - blob id
Returns:
  inline blob or empty if not present in the cache
See Also:
  `getAndRemove(int, long)`

#### add

    public boolean add(FbTransaction transaction,
                       InlineBlob blob)

Adds an inline blob to the cache for the transaction and blob id.

The inline blob is not stored in the cache if:

- `transaction` is not active
- `FbTransaction.getHandle()` is not equal to `InlineBlob.getTransactionHandle()`
- Adding the blob would exceed the maximum cache size

If the blob is stored, this cache is added as a transaction listener of `transaction`.

Parameters:
  `transaction` - transaction
  `blob` - inline blob
Returns:
  `true` if the blob was added to the cache, `false` otherwise

#### transactionStateChanged

    public void transactionStateChanged(FbTransaction transaction,
                                        TransactionState newState,
                                        TransactionState previousState)

Description copied from interface: `TransactionListener`
Signals that the transaction state changed.

Specified by:
  `transactionStateChanged` in interface `TransactionListener`
Parameters:
  `transaction` - `FbTransaction` that changed state

#### detached

    public void detached(FbDatabase database)

Description copied from interface: `DatabaseListener`
Called when the `database` connection has been detached

Specified by:
  `detached` in interface `DatabaseListener`
Parameters:
  `database` - The database object that was detached