public class Backend<T> where T : CacheCostCalculable

Represents a storage which stores a certain type of value in memory. It provides fast access, but limited storing size. The stored value type needs to conform to CacheCostCalculable, and its cacheCost will be used to determine the cost of size for the cache item.

You can config a MemoryStorage.Backend in its initializer by passing a MemoryStorage.Config value. or modifying the config property after it being created. The backend of MemoryStorage has upper limitation on cost size in memory and item count. All items in the storage has an expiration date. When retrieved, if the target item is already expired, it will be recognized as it does not exist in the storage. The MemoryStorage also contains a scheduled self clean task, to evict expired items from memory.

  • The config used in this storage. It is a value you can set and use to config the storage in air.



    public var config: Config { get set }
  • Creates a MemoryStorage with a given config.



    public init(config: Config)



    The config used to create the storage. It determines the max size limitation, default expiration setting and more.