29 Kasım 2022 Salı

HazelcastAPI QueryCache Arayüzü - Continuous Query Cache

Giriş
Şu satırı dahil ederiz
import com.hazelcast.map.QueryCache;
Açıklaması şöyle. Eğer birden fazla IMap nesnesine sorgu atmak istersek SQL kullanmak daha iyi.
QueryCache allows caching of the results of a query to improve the performance of read operations on the data. 
QueryCache also provides support for real-time updates to the cached data. When the data in the cache is updated, QueryCache automatically updates the cached result set, ensuring that the cached data is always up-to-date.
Bu arayüzü gerçekleştiren sınıf DefaultQueryCache. Hem client hem de server tarafında kullanılabilir. QueryCache  aslında filtrelenmiş bir IMap nesnesi gibidir.

constructor
Şöyle yaparız
String cacheName = ...;
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(cacheName);
ClientConfig clientConfig = ...;
clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);

IMap<Integer, Integer> map = ...;

QueryCache<Integer, Integer> queryCache = map
  .getQueryCache(cacheName, Predicates.alwaysTrue(), true);
Predicate için call stack şöyle. PutOperation esnasında Predicate çalışır ve gerekiyorsa QueryCacheEventPublisher ile gönderilir.
apply:59, TruePredicate (com.hazelcast.query.impl.predicates)
eval:54, QueryEventFilter (com.hazelcast.map.impl.query)
evaluateQueryEventFilter:77, AbstractFilteringStrategy (com.hazelcast.map.impl.event)
processQueryEventFilter:126, DefaultEntryEventFilteringStrategy (com.hazelcast.map.impl.event)
doFilter:85, DefaultEntryEventFilteringStrategy (com.hazelcast.map.impl.event)
getCQCEventTypeOrNull:152, QueryCacheEventPublisher (com.hazelcast.map.impl.event)
convertQueryCacheEventDataOrNull:122, QueryCacheEventPublisher (com.hazelcast.map.impl.event)
addEventToQueryCache:85, QueryCacheEventPublisher (com.hazelcast.map.impl.event)
postPublishEvent:275, MapEventPublisherImpl (com.hazelcast.map.impl.event)
publishEvent:232, MapEventPublisherImpl (com.hazelcast.map.impl.event)
publishEvent:196, MapEventPublisherImpl (com.hazelcast.map.impl.event)
publishEvent:184, MapEventPublisherImpl (com.hazelcast.map.impl.event)
afterRunInternal:87, BasePutOperation (com.hazelcast.map.impl.operation)
afterRun:225, MapOperation (com.hazelcast.map.impl.operation)
afterRun:368, OperationRunnerImpl (com.hazelcast.spi.impl.operationservice.impl)
call:297, OperationRunnerImpl (com.hazelcast.spi.impl.operationservice.impl)
run:258, OperationRunnerImpl (com.hazelcast.spi.impl.operationservice.impl)
run:486, OperationRunnerImpl (com.hazelcast.spi.impl.operationservice.impl)
process:197, OperationThread (com.hazelcast.spi.impl.operationexecutor.impl)
process:137, OperationThread (com.hazelcast.spi.impl.operationexecutor.impl)
executeRun:123, OperationThread (com.hazelcast.spi.impl.operationexecutor.impl)
run:102, HazelcastManagedThread (com.hazelcast.internal.util.executor)
Örnek
Şöyle yaparız. Burada maaşı yüz binden büyük olan çalışanlar QueryCache  içine alınıyor. Eğer alttaki IMap değişirse, sonuçlar QueryCache nesnesine de yansıtılıyor
IMap<String, Employee> employees = ...
QueryCache<String, Employee> highSalaryEmployeesCache = employees
  .getQueryCache("highSalaryEmployeesCache", new SqlPredicate("salary > 100000"));

Collection<Employee> highSalaryEmployees = highSalaryEmployeesCache.values();
for (Employee employee : highSalaryEmployees) {
  System.out.println(employee.getName());
}

size metodu
QueryCache nesnesinin içindeki nesne sayısını döner


Hiç yorum yok:

Yorum Gönder

THIRD-PARTY.txt Dosyası

Kullanılan harici kütüphanelerin sürümleri bu dosyada Dosyanın yolu şöyle hazelcast/licenses/THIRD-PARTY.txt