@Override public ICompletableFuture<V> getAsync(K key) { return cache.getAsync(key); }
@Override public ICompletableFuture<V> getAsync(K key, ExpiryPolicy expiryPolicy) { return cache.getAsync(key, expiryPolicy); }
@Override public ICompletableFuture<V> getAsync(K key) { return cache.getAsync(key); }
@Override public ICompletableFuture<V> getAsync(K key) { return cache.getAsync(key); }
@TimeStep(prob = 0.1) public void getAsync(ThreadState state) throws Exception { int key = state.randomInt(keyCount); Future<Long> future = cache.getAsync(key, expiryPolicy); future.get(); state.counter.getAsyncExpiry++; }
@TimeStep(prob = -1) public void get(ThreadState state) throws Exception { Integer key = state.randomInt(keyCount); ICompletableFuture<?> future = cache.getAsync(key); state.futureList.add(future); state.syncIfNecessary(state.iteration++); }
Future future = cache.getAsync("key1"); System.out.println("Get value as async with key \"key1\": " + future.get());
Future<Long> future = cache.getAsync(key, expiryPolicy); future.get(); counter.getAsyncExpiry++;
public static void main(String[] args) { // Run as a Hazelcast Client System.setProperty("hazelcast.jcache.provider.type", "client"); // Create the JCache CacheManager CacheManager manager = Caching.getCachingProvider().getCacheManager(); MutableConfiguration<String, String> configuration = new MutableConfiguration<String, String>(); // Expire entries after 1 minute configuration.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // Get a Cache called "myCache" and configure with 1 minute expiry Cache<String, String> myCache = manager.createCache("myCache", configuration); // Put and Get a value from "myCache" myCache.put("key", "value"); String value = myCache.get("key"); System.out.println(value); //ICache is a Hazelcast interface that extends JCache, provides more functionality ICache<String, String> icache = myCache.unwrap(ICache.class); //Async Get and Put using ICache interface icache.getAsync("key"); icache.putAsync("key", "value"); //ICache allows custom expiry per cache entry final ExpiryPolicy customExpiryPolicy = AccessedExpiryPolicy.factoryOf(Duration.TEN_MINUTES).create(); icache.put("key", "newValue", customExpiryPolicy); //Size of the Cache should reflect the ICache and JCache operations icache.size(); //Shutdown this Hazelcast Client manager.getCachingProvider().close(); } }
public static void main(String[] args) { // Run as a Hazelcast Member System.setProperty("hazelcast.jcache.provider.type", "server"); // Create the JCache CacheManager CacheManager manager = Caching.getCachingProvider().getCacheManager(); MutableConfiguration<String, String> configuration = new MutableConfiguration<String, String>(); // Expire entries after 1 minute configuration.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_MINUTE)); // Get a Cache called "myCache" and configure with 1 minute expiry Cache<String, String> myCache = manager.createCache("myCache", configuration); // Put and Get a value from "myCache" myCache.put("key", "value"); String value = myCache.get("key"); System.out.println(value); //ICache is a Hazelcast interface that extends JCache, provides more functionality ICache<String, String> icache = myCache.unwrap(ICache.class); //Async Get and Put using ICache interface icache.getAsync("key"); icache.putAsync("key", "value"); //ICache allows custom expiry per cache entry final ExpiryPolicy customExpiryPolicy = AccessedExpiryPolicy.factoryOf(Duration.TEN_MINUTES).create(); icache.put("key", "newValue", customExpiryPolicy); //Size of the Cache should reflect the ICache and JCache operations icache.size(); //Shutdown the underlying Hazelcast Cluster Member manager.getCachingProvider().close(); } }