StorageDelegate

class StorageDelegate<T : Any>(val cacheable: Boolean = false, initializer: () -> Storage<T>) : Storage<T>

A delegate class for managing storage.

Parameters

T

The type of object to be stored.

cacheable

Whether the storage should cache the item in memory.

initializer

A function to initialize the underlying storage.

Constructors

Link copied to clipboard
constructor(cacheable: Boolean = false, initializer: () -> Storage<T>)

Properties

Link copied to clipboard
private val cacheable: Boolean = false
Link copied to clipboard
private var cached: T?
Link copied to clipboard
private val delegate: Storage<T>
Link copied to clipboard
private var lock: Any

Functions

Link copied to clipboard
open override fun delete()

Delete an item from the storage and clear the cache if enabled.

Link copied to clipboard
open override fun get(): T?

Retrieve an item from the storage, using the cache if available.

Link copied to clipboard
open override fun save(item: T)

Save an item to the storage and optionally cache it.