private void checkProviders(Cache<K, GridBucketState> cache) { CacheManager cacheManager = cache.getCacheManager(); if (cacheManager == null) { return; } CachingProvider cachingProvider = cacheManager.getCachingProvider(); if (cachingProvider == null) { return; } String providerClassName = cachingProvider.getClass().getName(); incompatibleProviders.forEach((providerPrefix, recommendation) -> { if (providerClassName.startsWith(providerPrefix)) { String message = "The Cache provider " + providerClassName + " is incompatible with Bucket4j, " + recommendation; throw new UnsupportedOperationException(message); } }); }
private void checkProviders(Cache<K, GridBucketState> cache) { CacheManager cacheManager = cache.getCacheManager(); if (cacheManager == null) { return; } CachingProvider cachingProvider = cacheManager.getCachingProvider(); if (cachingProvider == null) { return; } String providerClassName = cachingProvider.getClass().getName(); incompatibleProviders.forEach((providerPrefix, recommendation) -> { if (providerClassName.startsWith(providerPrefix)) { String message = "The Cache provider " + providerClassName + " is incompatible with Bucket4j, " + recommendation; throw new UnsupportedOperationException(message); } }); }
/** {@inheritDoc} */ public String getCacheProviderName() { return "jCache:" + featuresCache.getName() + ":" + featuresCache.getCacheManager().getCachingProvider().toString(); }
@Override public void execute(Context context) throws Exception { Cache<Integer, User> userCache = context.getUserCache(); userCache.getCacheManager().getCachingProvider().close(); System.exit(0); }
/** * @see org.jsr107.tck.testutil.ExcludeListExcluder#isExcluded(String) */ @Override protected boolean isExcluded(String methodName) { return "simpleAPINoGenericsAndNoTypeEnforcementStoreByReference".equals(methodName) && !cacheManager.getCachingProvider().isSupported(OptionalFeature.STORE_BY_REFERENCE) || super.isExcluded(methodName); } };
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(); } }