Object Type: AbstractCache

The cache:AbstractCache object is used for custom implementations of the Ballerina cache. Any custom cache implementation should be object-wise similar.

Methods

put

Adds the given key value pair to the cache.

get

Returns the cached value associated with the provided key.

invalidate

Discards a cached value from the cache.

invalidateAll

Discards all the cached values from the cache.

hasKey

Checks whether the given key has an associated cache value.

keys

Returns all keys from the cache.

size

Returns the current size of the cache.

capacity

Returns the capacity of the cache.

put

function put(string key, any value, decimal maxAge) returns Error?
Isolated Function

Adds 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 value to be cached

  • value any
  • Value to be cached

  • maxAge decimal (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 or Error if any error occurred while inserting the entry to the cache

get

function get(string key) returns any | Error
Isolated Function

Returns the cached value associated with the provided key.

Parameters

  • key string
  • The key used to retrieve the cached value

Return Type

(any | Error)

The cached value associated with the given key or an Error if the provided cache key is not available or if any error occurred while retrieving from the cache

invalidate

function invalidate(string key) returns Error?
Isolated Function

Discards 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 or an Error if the provided cache key is not available or if any error occurred while discarding from the cache

invalidateAll

function invalidateAll() returns Error?
Isolated Function

Discards all the cached values from the cache.

Return Type

(Error?)

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

hasKey

function hasKey(string key) returns boolean
Isolated Function

Checks whether the given key has an associated cache value.

Parameters

  • key string
  • The key to be checked

Return Type

(boolean)

true if an associated cache value is available for the provided key or false if there is not a cache value associated with the provided key

keys

function keys() returns string[ ]
Isolated Function

Returns all keys from the cache.

Return Type

(string[ ])

Array of all the keys from the cache

size

function size() returns int
Isolated Function

Returns the current size of the cache.

Return Type

(int)

The size of the cache

capacity

function capacity() returns int
Isolated Function

Returns the capacity of the cache.

Return Type

(int)

The capacity of the cache