ballerina.caching package

public struct Cache

Map which stores all of the caches.

Field Name Data Type Description Default Value
name string name of the cache
expiryTimeMillis int cache expiry time in ms
capacity int capacity of the cache
evictionFactor float eviction factor to be used for cache eviction
entries map map which contains the cache entries
  • < Cache > get ( string key ) ( any )

    Returns the cached value associated with the given key. Returns null if the provided key does not exist in the cache.

    Parameter Name Data Type Description
    key string key which is used to retrieve the cached value

    Return Variable Data Type Description
    any
  • < Cache > put ( string key , any value )

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

    Parameter Name Data Type Description
    key string value which should be used as the key
    value any value to be cached
  • < Cache > remove ( string key )

    Removes a cached value from a cache.

    Parameter Name Data Type Description
    key string key of the cache entry which needs to be removed
  • < Cache > size ( ) ( int )

    Returns the size of the cache.

    Return Variable Data Type Description
    int

public function createCache ( string name , int expiryTimeMillis , int capacity , float evictionFactor ) ( Cache )

Creates a new cache.

Parameter Name Data Type Description
name string name of the cache
expiryTimeMillis int expiryTime of the cache in ms
capacity int capacitry of the cache which should be greater than 0
evictionFactor float eviction factor to be used for cache eviction