A partitioned cache can also be fronted by a
Near cache which is a smaller local cache that stores the most recently or most frequently accessed data. Just like with a partitioned cache, you can control the size of the near cache and its eviction policies.
Near caches can be created directly on client nodes by passing
NearConfiguration into the
Ignite.getOrCreateNearCache(NearConfiguration) nodes. Use
Ignite.getOrCreateCache(CacheConfiguration, NearCacheConfiguration) method if you need both start a distributed cache dynamically and create a near-cache for it.
// Create near-cache configuration for "myCache". NearCacheConfiguration<Integer, Integer> nearCfg = new NearCacheConfiguration<>(); // Use LRU eviction policy to automatically evict entries // from near-cache, whenever it reaches 100_000 in size. nearCfg.setNearEvictionPolicy(new LruEvictionPolicy<>(100_000)); // Create a distributed cache on server nodes and // a near cache on the local node, named "myCache". IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache( new CacheConfiguration<Integer, Integer>("myCache"), nearCfg);
<bean class="org.apache.ignite.configuration.CacheConfiguration"> <property name="name" value="myCache" /> <property name="nearConfiguration"> <bean class="org.apache.ignite.configuration.NearCacheConfiguration"> <property name="nearEvictionPolicy"> <bean class="org.apache.ignite.cache.eviction.lru.LruEvictionPolicy"> <property name="maxSize" value="100000"/> </bean> </property> </bean> </property> </bean>
In a majority of use cases, whenever utilizing Ignite with affinity colocation, near caches should not be used. If computations are collocated with the corresponding partition cache nodes then the near cache is simply not needed because all the data is available locally in the partitioned cache. However, there are cases when it is simply impossible to send computations to remote nodes. For cases like this near caches can significantly improve scalability and the overall performance of the application.
Near caches are fully transactional and get updated or invalidated automatically whenever the data changes on the servers.
Near Caches on Server Nodes
Whenever accessing data from
PARTITIONED caches on the server side in a non-collocated fashion, you may need to configure near-caches on the server nodes via
Most configuration parameters available on
CacheConfiguration that make sense for the near cache are inherited from the server configuration. For example, if the server cache has an
ExpiryPolicy, entries in the near cache will be expired based on the same policy.
Parameters listed in the table below are not inherited from the server configuration and provided separately, via the
Eviction policy for the near cache.
Start size for near cache.