Object - cache : Cache

The cache:Cache object, which is used for all the cache-related operations. It is not recommended to insert () as the value of the cache since it doesn't make any sense to cache a nil.

Constructor

__init

(CacheConfig cacheConfig)

  • cacheConfig CacheConfig {}
  • Configurations for the cache:Cache object

Methods

Adds the given key value pair to the cache.
Returns the cached value associated with the provided key.
Discards a cached value from the cache.
Discards all the cached values from the cache.
Checks whether the given key has an associated cached value.
Returns a list of all the keys from the cache.
Returns the size of the cache.
Returns the capacity of the cache.

put

(string key, any value, int maxAgeInSeconds)

returns Error?

Adds the given key value pair to the cache. If the cache previously contained a value associated with the provided key, the old value wil be replaced by the newly-provided value.

Parameters

  • key string
  • Key of the value to be cached

  • value any
  • Value to be cached. Value should not be ()

  • maxAgeInSeconds int (default -1)
  • The time in seconds for which the cache entry is valid. If the value is '-1', the entry is valid forever.

  • Return Type

    (Error?)
  • () if successfully added to the cache or Error if a () value is inserted to the cache.

get

(string key)

returns any | Error

Returns the cached value associated with the provided key.

Parameters

  • key string
  • Key of the cached value, which should be retrieved

  • Return Type

    (any | Error)
  • The cached value associated with the provided key or an Error if the provided cache key is not exisiting in the cache or any error occurred while retrieving the value from the cache.

invalidate

(string key)

returns Error?

Discards a cached value from the cache.

Parameters

  • key string
  • Key of the cache value, which needs to be discarded from the cache

  • Return Type

    (Error?)
  • () if successfully discarded the value or an Error if the provided cache key is not present in the cache or if any error occurred while discarding the value from the cache.

invalidateAll

()

returns Error?

Discards all the cached values from the cache.

  • Return Type

    (Error?)
  • () if successfully discarded all the values from the cache or an Error if any error occurred while discarding all the values from the cache.

hasKey

(string key)

returns boolean

Checks whether the given key has an associated cached value.

Parameters

  • key string
  • The key to be checked in the cache

  • Return Type

    (boolean)
  • true if a cached value is available for the provided key or false if there is no cached value associated for the given key

keys

()

returns string[]

Returns a list of all the keys from the cache.

  • Return Type

    (string[])
  • Array of all the keys from the cache

size

()

returns int

Returns the size of the cache.

  • Return Type

    (int)
  • The size of the cache

capacity

()

returns int

Returns the capacity of the cache.

  • Return Type

    (int)
  • The capacity of the cache