Functions of ballerina.caching package
public function <Cache 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.
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
cache | Cache | key: key which is used to retrieve the cached value |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
key | string | key which is used to retrieve the cached value |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
any | any: The cached value associated with the given key |
public function <Cache cache> put(string key, any value)
Adds the given key, value pair to the provided cache.
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
cache | Cache | key: value which should be used as the key |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
key | string | value which should be used as the key |
value | any | value to be cached |
public function <Cache cache> remove(string key)
Removes a cached value from a cache.
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
cache | Cache | key: key of the cache entry which needs to be removed |
Parameters:
Parameter Name | Data Type | Description |
---|---|---|
key | string | key of the cache entry which needs to be removed |
public function <Cache cache> size() (int)
Returns the size of the cache.
Receiver:
Receiver Name | Data Type | Description |
---|---|---|
cache | Cache |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
int | int: The size of the cache |
public function createCache(string name, int expiryTimeMillis, int capacity, float evictionFactor) (Cache)
Creates a new cache.
Parameters:
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 |
Return Parameters:
Return Variable | Data Type | Description |
---|---|---|
Cache | cache: a new cache |
Structs of ballerina.caching package
public struct Cache
Map which stores all of the caches.
Fields:
Field Name | Data Type | Description |
---|---|---|
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 |