MemoryStorage
public class MemoryStorage<T> : StorageDelegate<T>, @unchecked Sendable where T : Decodable, T : Encodable, T : Sendable
MemoryStorage
provides an in-memory storage solution for objects of type T
.
It conforms to the StorageDelegate
protocol, enabling it to interact seamlessly with other components expecting a storage delegate.
This class is ideal for temporary storage where persistence across app launches is not required.
The generic type T
must conform to Codable
to ensure that objects can be encoded and decoded when written to and read from memory, respectively.
Parameters
T
|
The type of the objects to be stored. Must conform to |
-
Initializes a new instance of
MemoryStorage
.This initializer creates a
MemoryStorage
instance that acts as a delegate for an in-memory storage mechanism. It allows for the optional caching of data based on thecacheable
parameter.Declaration
Swift
public init(cacheable: Bool = false)
Parameters
cacheable
A Boolean value indicating whether the stored data should be cached. Defaults to
false
, which means that caching is not enabled by default. When set totrue
, it enables caching based on the implementation details of theMemory<T>
storage strategy.