shutdown
For every key in the container having a shutdown closure, invoke the closure. Designed to be invoked during an explicit app shutdown process or in a reference type’s deinit
.
func shutdown()
For every key in the container having a shutdown closure, invoke the closure. Designed to be invoked during an explicit app shutdown process or in a reference type’s deinit
.
func shutdown()
import Vapor
Vapor is a framework for building server applications, APIs and websites in Swift. It provides a safe, performant and scalable foundation for building large complex backends.
struct Storage
A container providing arbitrary storage for extensions of an existing type, designed to obviate the problem of being unable to add stored properties to a type in an extension. Each stored item is keyed by a type conforming to StorageKey
protocol.
init(logger: Logger = .init(label: "codes.vapor.storage"))
Create a new Storage
container using the given logger.
subscript<Key>(key: Key.Type) -> Key.Value? where Key : StorageKey { get set }
Read/write access to values via keyed subscript.
subscript<Key>(key: Key.Type, default defaultValue: @autoclosure () -> Key.Value) -> Key.Value where Key : StorageKey { mutating get }
Read access to a value via keyed subscript, adding the provided default value to the storage if the key does not already exist. Similar to Swift/Dictionary/subscript(key:default:)
. The defaultValue
autoclosure is evaluated only when the key does not already exist in the container.
func asyncShutdown() async
For every key in the container having a shutdown closure, invoke the closure. Designed to be invoked during an explicit app shutdown process or in a reference type’s deinit
.
mutating func clear()
Delete all values from the container. Does not invoke shutdown closures.
func contains<Key>(_ key: Key.Type) -> Bool
Test whether the given key exists in the container.
func get<Key>(_ key: Key.Type) -> Key.Value? where Key : StorageKey
Get the value of the given key if it exists and is of the proper type.
mutating func set<Key>(_ key: Key.Type, to value: Key.Value?, onShutdown: ((Key.Value) throws -> ())? = nil) where Key : StorageKey
Set or remove a value for a given key, optionally providing a shutdown closure for the value.
mutating func setWithAsyncShutdown<Key>(_ key: Key.Type, to value: Key.Value?, onShutdown: ((Key.Value) async throws -> ())? = nil) async where Key : StorageKey
Set or remove a value for a given key, optionally providing an async shutdown closure for the value.