InMemoryHeaders

A thread-safe, in-memory implementation of SuspendMutableMap for storing string key-value pairs, typically used for managing headers in a concurrent environment.

This class ensures that all operations on the underlying map are atomic and safe to call from multiple coroutines simultaneously. It uses a Mutex to protect access to the internal MutableMap. The suspendable functions provide a non-blocking API for asynchronous access.

The collections returned by keys, values, and entries are immutable snapshots of the map's state at the time of the call, ensuring thread safety when iterating over them.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open suspend override fun clear()

Removes all of the mappings from this map. The map will be empty after this call returns. This operation is performed atomically and is thread-safe.

Link copied to clipboard
open suspend override fun containsKey(key: String): Boolean

Checks if this map contains a mapping for the specified key. This operation is thread-safe.

Link copied to clipboard
open suspend override fun entries(): Set<MutableMap.MutableEntry<String, String>>

Returns an immutable snapshot of all key-value pairs in this map. The returned set is a copy and will not reflect subsequent changes to the map. This operation is thread-safe.

Link copied to clipboard
open suspend override fun get(key: String): String?

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. This operation is thread-safe.

Link copied to clipboard
open suspend override fun isEmpty(): Boolean

Checks if this map contains no key-value mappings. This operation is thread-safe.

Link copied to clipboard
open suspend override fun keys(): Set<String>

Returns an immutable snapshot of all keys in this map. The returned set is a copy and will not reflect subsequent changes to the map. This operation is thread-safe.

Link copied to clipboard
open suspend override fun put(key: String, value: String): String?

Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced. This operation is performed atomically and is thread-safe.

Link copied to clipboard
open suspend override fun putAll(from: Map<out String, String>)

Copies all of the mappings from the specified map from to this map. These mappings will replace any mappings that this map had for any of the keys that are currently in the specified map. This operation is performed atomically and is thread-safe.

Link copied to clipboard
open suspend override fun remove(key: String): String?

Removes the mapping for a key from this map if it is present. This operation is performed atomically and is thread-safe.

Link copied to clipboard
open suspend override fun size(): Int

Returns the number of key-value mappings in this map. This operation is thread-safe.

Link copied to clipboard
open suspend override fun values(): List<String>

Returns an immutable snapshot of all values in this map. The returned list is a copy and will not reflect subsequent changes to the map. This operation is thread-safe.