Object -
cache
:
AbstractCache
Represents the Ballerina AbstractCache
object and cache-related operations.
Any custom cache implementation should be object-wise similar.
Methods
Add the given key value pair to the cache. If the cache previously contained a value associated with the key, the old value is replaced by the new value.
Return the cached value associated with the given key.
Discard a cached value from the cache.
Discard all the cached values from the cache.
Checks whether the given key has an associated cache value.
Returns all keys from the cache.
Returns the size of the cache.
Returns the capacity of the cache.
Add the given key value pair to the cache. If the cache previously contained a value associated with the key, the old value is replaced by the new value.
Parameters
- key string
-
Key of the cached value
- value any
-
Value to be cached
- maxAgeInSeconds int (default -1)
-
The time in seconds during which the cache entry is valid. '-1' means, the entry is valid forever.
-
Return Type
(Error?) ()
if successfully added to the cache orError
if any error occurred while inserting the entry to the cache.
Return the cached value associated with the given key.
Parameters
- key string
-
Key, which is used to retrieve the cached value
-
Return Type
(any | Error) The cached value associated with the given key,
Error
if the provided cache key is not available, or if any error occurred while retrieving from the cache.
Discard a cached value from the cache.
Parameters
- key string
-
Key of the cache entry, which needs to be discarded
-
Return Type
(Error?) ()
if successfully discarded,Error
if the provided cache key is not available, or if any error occurred while discarding from the cache.
Discard all the cached values from the cache.
-
Return Type
(Error?) ()
if successfully discarded all orError
if any error occurred while discarding all from the cache.
Checks whether the given key has an associated cache value.
Parameters
- key string
-
The key to be checked
-
Return Type
(boolean) Whether an associated cache value is available in the cache or not
Returns all keys from the cache.
-
Return Type
(string[]) Array of all keys from the cache