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. 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 orError
if a()
value is inserted to the cache.
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.
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 anError
if the provided cache key is not present in the cache or if any error occurred while discarding the value from the cache.
Discards all the cached values from the cache.
-
Return Type
(Error?) ()
if successfully discarded all the values from the cache or anError
if any error occurred while discarding all the values from the cache.
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 orfalse
if there is no cached value associated for the given key
Returns a list of all the keys from the cache.
-
Return Type
(string[]) Array of all the keys from the cache