Object - cache : Cache

Represents a Ballerina Cache which can hold multiple entries and remove entries based on time and size.

Constructor

__init

(int expiryTimeInMillis, int capacity, float evictionFactor)

  • expiryTimeInMillis int 900000
  • Time since its last access in which the cache will be expired.

  • capacity int 100
  • Maximum number of entries allowed.

  • evictionFactor float 0.25
  • The factor which the entries will be evicted once the cache full.

Methods

hasKey

(string key)

returns boolean

Checks whether the given key has an associated cache value.

Parameters

  • key string
  • The key to be checked.

  • Return Type

    (boolean)
  • true if the given key has an associated value, false otherwise.

size

()

returns int

Returns the size of the cache.

  • Return Type

    (int)
  • The size of the cache.

put

Adds the given key, value pair to the provided cache.

Parameters

  • key string
  • Value which should be used as the key.

  • value any
  • Value to be cached.

get

(string key)

returns any

Returns the cached value associated with the given key. If the provided cache key is not found, () will be returned.

Parameters

  • key string
  • Key which is used to retrieve the cached value.

  • Return Type

    (any)
  • The cached value associated with the given key.

remove

Removes a cached value from a cache.

Parameters

  • key string
  • Key of the cache entry which needs to be removed.

keys

()

returns string

Returns all keys from current cache.

  • Return Type

    (string)
  • Array of all keys from the current cache.