Ballerina API Documentation

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 NameData TypeDescription
cacheCachekey: key which is used to retrieve the cached value

Parameters:

Parameter NameData TypeDescription
keystringkey which is used to retrieve the cached value

Return Parameters:

Return VariableData TypeDescription
anyThe 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 NameData TypeDescription
cacheCachekey: value which should be used as the key

Parameters:

Parameter NameData TypeDescription
keystringvalue which should be used as the key
valueanyvalue to be cached

public function <Cache cache> remove(string key)

Removes a cached value from a cache.

Receiver:

Receiver NameData TypeDescription
cacheCachekey: key of the cache entry which needs to be removed

Parameters:

Parameter NameData TypeDescription
keystringkey of the cache entry which needs to be removed

public function <Cache cache> size() (int)

Returns the size of the cache.

Receiver:

Receiver NameData TypeDescription
cacheCache

Return Parameters:

Return VariableData TypeDescription
intint: The size of the cache

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

Creates a new cache.

Parameters:

Parameter NameData TypeDescription
namestringname of the cache
expiryTimeMillisintexpiryTime of the cache in ms
capacityintcapacitry of the cache which should be greater than 0
evictionFactorfloateviction factor to be used for cache eviction

Return Parameters:

Return VariableData TypeDescription
Cachecache: a new cache


Structs of ballerina.caching package

public struct Cache

Map which stores all of the caches.

Fields:

Field Name Data Type Description
namestringname of the cache
expiryTimeMillisintcache expiry time in ms
capacityintcapacity of the cache
evictionFactorfloateviction factor to be used for cache eviction
entriesmapmap which contains the cache entries


Menu

  • Functions
    • <Cache> get(string key) (any )
    • <Cache> put(string key, any value)
    • <Cache> remove(string key)
    • <Cache> size() (int )
    • createCache(string name, int expiryTimeMillis, int capacity, float evictionFactor) (Cache )
  • Structs
    • Cache

Copyright 2017 Ballerina API Documentation