---
title: "Hazelcast Cache Manager"
canonical: "https://onesaitplatform.refined.site/space/DOCT/2221605989/Hazelcast%20Cache%20Manager"
format: markdown
---
> Macro (toc)

# <span style="color: #000000">Introduction</span>

<span style="color: #000000">The cache can be defined as a high-speed data storage layer that temporarily stores information. In this way, in future requests, the data can be served more quickly and easily, increasing the process speed of running programs.</span>

<span style="color: #000000">With the use of caches you get a number of advantages: </span>

- <span style="color: #000000">**Improved application performance**</span><span style="color: #000000">. </span>
- <span style="color: #000000">**Cost reduction**</span><span style="color: #000000">. With traditional databases and disk-based hardware, increasing resources does not imply that improvements in latency will be obtained as a cache usually does. </span>
- <span style="color: #000000">**Reduction of the load**</span><span style="color: #000000"> on the back end. </span>
- <span style="color: #000000">Increased reading performance, reduced latency and much higher request speeds compared to a disk-based database.</span>

<span style="color: #000000">This example explains how to use the Cache Administration functionality where to store different types of data such as results of database queries, requests and responses of APIs, web pages, user session information, among others.</span>

<span style="color: #000000">This service uses </span><span style="color: #000000">**Hazelcast**</span><span style="color: #000000">, a distributed storage system, which helps manage data and distribute the processing using memory storage and parallel execution. Hazelcast’s distributed architecture provides redundancy for continuous cluster up-time and always available data to serve the most demanding applications. Capacity grows elastically with demand, without compromising performance or availability.</span>

<span style="color: #000000">One of the uses that can be given to the management of caches is to make the data of a file or a database available from the API. Simply reading the data and loading it into the cache would allow access to it with the different endpoints.</span>

# <span style="color: #000000">Creating a Cache</span>

<span style="color: #000000">For this, it is necessary to use a profile with administrator role and go to the menu: </span><span style="color: #000000">**Administration > Cache Management**</span><span style="color: #000000">.</span>

![image](media://b6eb3170-7949-4005-ab62-8a7db067ca19)

<span style="color: #000000">Once in the Cache Management screen, click on "Create":</span>

![image](media://358761a5-e36e-40d6-830f-37b6d330220d)

<span style="color: #222222">To create a new cache it is necessary to indicate the name, type, maximum size policy, size and eviction policy.</span>

![image](media://3604d005-fd70-4588-9f84-1c372ef56d3b)

Currently, only the map type cache is supported, whose maximum size policies can be:

- ***PER_NODE***: Maximum number of map entries in each cluster member. This is the default policy.
- ***PER_PARTITION***: Maximum number of map entries within each partition.
- ***USED_HEAP_SIZE***: Maximum used heap size in megabytes per map for each instance.
- ***USED_HEAP_PERCENTAGE***: Maximum used heap size percentage per map for each instance
- ***FREE_HEAP_SIZE***: Minimum free heap size in megabytes for each JVM.
- ***FREE_HEAP_PERCENTAGE***: Minimum free heap size percentage for each JVM.
- ***USED_NATIVE_MEMORY_SIZE***: Maximum used native memory size in megabytes per map for each instance.
- ***USED_NATIVE_MEMORY_PERCENTAGE***: Maximum used native memory size percentage per map for each instance.
- ***FREE_NATIVE_MEMORY_SIZE***: Minimum free native memory size in megabytes for each
- instance.
- ***FREE_NATIVE_MEMORY_PERCENTAGE***: Minimum free native memory size percentage for each instance.

And whose eviction policies are:

- ***LRU***: Least Recently Used.
- ***LFU***: Least Frequently Used.
- ***NONE***: If set, no items are evicted and the property max-size described below is ignored.
- ***RANDOM***.

# REST API

<span style="color: #222222">To work with the cache it is necessary to know the specific REST API for it. It can be accessed from the APIs section of the platform (</span><span style="color: #222222">[https://lab.onesaitplatform.com/controlpanel/swagger-ui.html](https://lab.onesaitplatform.com/controlpanel/swagger-ui.html)</span><span style="color: #222222">).</span>

![image](media://38495f34-4b09-44ef-9cd7-7cc8f51302f5)

<span style="color: #000000">Once the cache is created, information can be inserted into it with the last two endpoints, by entering the desired key-value pairs. </span><span style="color: #222222">In this case we will enter several values ​​at the same time for the user cache.</span>

![image](media://61765014-9d4a-48e1-b6ef-d1d59e7a6c72)

<span style="color: #222222">Subsequently, the application can query the data with the obtaining operations, indicating the cache identifier and the keys of the desired values. </span>If we want to check which users have registered a specific day,<span style="color: #222222"> we will enter the day key:</span>

![image](media://0440a958-261b-4d72-87ef-1e1c75e4050b)

<span style="color: #222222">The answer that will return the request is the following:</span>

![image](media://df36bd8e-beaf-4223-9916-2140487d195b)

<span style="color: #222222">If you want to know all the key values ​​or only one, you must use the get methods of the API, </span><span style="color: #222222">*getAll*</span><span style="color: #222222"> and </span><span style="color: #222222">*get/{Key}*</span><span style="color: #222222"> respectively.</span>

<span style="color: #000000">In this way you can have control of the cached data, updating and consulting them.</span>

<span style="color: #000000">To clear the cache, you only need to know its identifier, </span><span style="color: #222222">and all data will be deleted.</span>

![image](media://84aaceba-2c3d-473a-85c6-3dd652c60bbb)