Google News
logo
Hazelcast - Interview Questions
What are near-cache and how do they work in Hazelcast?
Near caches, also known as near-cache maps, are a feature in Hazelcast that improve read performance by caching frequently accessed data in-memory on client-side nodes.

They work by storing a copy of the most frequently accessed or recently accessed data from a distributed Hazelcast map in-memory on the client node itself, reducing the need for frequent remote access to the distributed cluster for read operations.

Here's how near caches work in Hazelcast :

Cache Coherence :
* When a client node accesses data from a distributed Hazelcast map, the data is retrieved from the nearest member node in the cluster where the data resides.
* The retrieved data is then stored in the near cache on the client node, along with a timestamp indicating when the data was fetched from the cluster.

Read Operations :
* Subsequent read operations for the same data are first checked against the near cache on the client node. If the data is found in the near cache and is not stale (i.e., not expired), it is returned directly from the near cache without the need to access the distributed cluster.
* This reduces the latency and overhead associated with remote network calls to the cluster, resulting in faster read operations and improved application performance.

Invalidation and Eviction :
* Near caches support invalidation and eviction mechanisms to ensure data coherence and cache consistency.
* When data is updated or invalidated in the distributed Hazelcast map, corresponding entries in the near cache are marked as invalid or evicted to ensure that stale data is not served from the cache.

Configuration Options :
* Hazelcast provides various configuration options for near caches, allowing developers to customize cache behavior and eviction policies based on application requirements.
* Configuration options include cache size limits, time-to-live (TTL) and time-to-idle (TTI) expiration policies, eviction policies (such as LRU or LFU), and invalidation settings.

Synchronous and Asynchronous Updates :
* Near caches support both synchronous and asynchronous update modes, allowing developers to control whether updates to the near cache are performed synchronously (immediately) or asynchronously (deferred).
* Synchronous updates ensure that the near cache is always consistent with the distributed map but may introduce additional latency for write operations. Asynchronous updates reduce latency but may temporarily result in stale data in the near cache until updates are propagated.

Client-Side Caching :
* Near caches operate on the client-side nodes in a Hazelcast cluster, allowing each client node to maintain its own independent cache of frequently accessed data.
* This client-side caching approach reduces the load on the server-side nodes in the cluster and improves scalability by distributing caching responsibilities across client nodes.
Advertisement