How to work with a cache
When you create the OlpClientSettings instance, an in-memory cache is automatically created with the default capacity of 2 MB. You can set new cache capacity as well as get the current cache capacity and size.
To work with the cache:
-
Create the
OlpClientSettingsinstance.For instructions, see Create platform client settings.
-
Get the LRU cache instance.
const cache = settings.cache; -
Do one of the following:
-
To get the maximum cache capacity, call the
getCapacitymethod.cache.getCapacity();You receive the total amount of memory that can be consumed by the cache in MB.
-
To get the current cache size, call the
getSizemethod.cache.getSize();You receive the total size of all the objects in the cache in MB.
-
To change the cache capacity, call the
setCapacitymethod with the new capacity in MB.
-
Note
If the new capacity is smaller than the current cache size, all items are evicted until the cache shrinks to the specified capacity.
cache.setCapacity("new cache capacity in MB");Updated 14 days ago