Vapor Documentation

Protocol Cache

public protocol Cache  

Codable key-value pair cache.

Default Implementations

set(_:​to:​expires​In:​)

public func set<T>(_ key: String, to value: T?, expiresIn expirationTime: CacheExpirationTime?) -> EventLoopFuture<Void>
        where T: Encodable

Sets an encodable value into the cache with an expiry time. Existing values are replaced. If nil, removes value.

delete(_:​)

public func delete(_ key: String) -> EventLoopFuture<Void>

get(_:​)

public func get<T>(_ key: String) -> EventLoopFuture<T?>
        where T: Decodable

Gets a decodable value from the cache. Returns nil if not found.

get(_:​as:​)

func get<T>(_ key: String, as type: T.Type) async throws -> T? where T: Decodable  

Gets a decodable value from the cache. Returns nil if not found.

set(_:​to:​)

func set<T>(_ key: String, to value: T?) async throws where T: Encodable  

Sets an encodable value into the cache. Existing values are replaced. If nil, removes value.

set(_:​to:​expires​In:​)

func set<T>(_ key: String, to value: T?, expiresIn expirationTime: CacheExpirationTime?) async throws where T: Encodable  

Sets an encodable value into the cache with an expiry time. Existing values are replaced. If nil, removes value.

delete(_:​)

func delete(_ key: String) async throws  

get(_:​)

func get<T>(_ key: String) async throws -> T? where T: Decodable  

Gets a decodable value from the cache. Returns nil if not found.

Requirements

get(_:​as:​)

func get<T>(_ key: String, as type: T.Type) -> EventLoopFuture<T?>
        where T: Decodable

Gets a decodable value from the cache. Returns nil if not found.

set(_:​to:​)

func set<T>(_ key: String, to value: T?) -> EventLoopFuture<Void>
        where T: Encodable

Sets an encodable value into the cache. Existing values are replaced. If nil, removes value.

set(_:​to:​expires​In:​)

func set<T>(_ key: String, to value: T?, expiresIn expirationTime: CacheExpirationTime?) -> EventLoopFuture<Void>
        where T: Encodable

Sets an encodable value into the cache with an expiry time. Existing values are replaced. If nil, removes value.

`for`(_:​)

func `for`(_ request: Request) -> Self

Creates a request-specific cache instance.