private com.atlassian.cache.Cache getCache() { return cacheFactory.getCache(cacheName); }
public HazelcastHybridCachedReference(String name, CacheFactory localFactory, final IMap<ReferenceKey, Long> versionMap, final Supplier<V> supplier, HazelcastCacheManager cacheManager) { super(name, cacheManager); Supplier<Versioned<V>> localSupplier = new Supplier<Versioned<V>>() { @Override public Versioned<V> get() { long version = getVersion(); V value = supplier.get(); if (value == null) { throw new CacheException("The Supplier for cached reference '" + getName() + "'returned null. Null values are not supported."); } return new Versioned<V>(value, version); } }; this.versionMap = versionMap; this.localReference = localFactory.getCachedReference(name, localSupplier, getCacheSettings()); }
private com.atlassian.cache.Cache getCache() { return cacheFactory.getCache(cacheName); }
public DefaultReadOnlyApplicationLinkService(final ApplicationLinkService applicationLinkService, final ApplicationLinkRequestFactoryFactory requestFactoryFactory, final TransactionTemplate transactionTemplate, final EventPublisher eventPublisher, final CacheFactory cacheFactory) throws InvocationTargetException, IllegalAccessException { this.applicationLinkService = applicationLinkService; this.requestFactoryFactory = requestFactoryFactory; this.transactionTemplate = transactionTemplate; this.eventPublisher = eventPublisher; // ROTP-975 expire entries after some time to pick up applinks created by applinks 2 code links = cacheFactory.getCachedReference(DefaultReadOnlyApplicationLinkService.class.getName() + ".links", new LinkSupplier(), newCacheSettings()); }
@NotNull private Cache getCache() { return cacheFactory.getCache(cacheName); }
protected CachedReference<Long> makeReference() { // Build a Cache using the builder Supplier<Long> supplier = new Supplier<Long>() { private long value = 100; @Override public Long get() { return value++; } }; return factory.getCachedReference("mycache", supplier, settingsBuilder().build()); }
private Cache getCache() { String cacheName = underlyingPropertySetFactory.getClass().getName() + ".propertysets"; return cacheFactory.getCache(cacheName); }
private CachedReference<Long> makeExceptionalReference() { Supplier<Long> supplier = new Supplier<Long>() { private boolean called = false; @Override public Long get() { if (called) { return 42L; } called = true; throw new IllegalArgumentException(); } }; return factory.getCachedReference("mycache", supplier, settingsBuilder().build()); }
private Cache getUserCache() { synchronized(this) { if (userCacheName == null) userCacheName = getCacheKey(CACHE_SUFFIX_USERS); } return cacheFactory.getCache(userCacheName); }
@Test public void testOnSet() throws Exception { Supplier<String> supplier = mock(Supplier.class); when(supplier.get()).thenReturn("SET"); CachedReference<String> reference = factory.getCachedReference("set", supplier, settingsBuilder().build()); CachedReferenceListener listener = mock(CachedReferenceListener.class); reference.addListener(listener, true); reference.get(); ArgumentCaptor<CachedReferenceEvent> captor = ArgumentCaptor.forClass(CachedReferenceEvent.class); verify(listener, timeout(1000)).onSet(captor.capture()); CachedReferenceEvent<String> event = captor.getValue(); assertEquals("SET", event.getValue()); }
private Cache getRepositoryCache() { synchronized(this) { if (repositoryCacheName == null) repositoryCacheName = getCacheKey(CACHE_SUFFIX_REPOSITORIES); } return cacheFactory.getCache(repositoryCacheName); }
public HazelcastAsyncHybridCachedReference(String name, CacheFactory localFactory, final ITopic<ReferenceKey> topic, final Supplier<V> supplier, HazelcastCacheManager cacheManager, CacheSettings settings) { super(name, cacheManager); this.localReference = localFactory.getCachedReference(name, supplier, settings); listener = new AsyncInvalidationListener(cacheManager.getHazelcastInstance().getCluster(), localReference, topic); }
private Cache getUserROFlagCache() { synchronized(this) { if (userROCacheName == null) userROCacheName = getCacheKey(CACHE_SUFFIX_USERS_RO); } return cacheFactory.getCache(userROCacheName); }
private CachedReference<Long> makeNullReference() { return factory.getCachedReference("mycache", nullSupplier(), settingsBuilder().build()); }
protected Cache<String, Long> makeStatisticsDisabledCache() { final Cache<String, Long> cache = factory.getCache("mycache", null, statsDisabledSettings); assertEmpty(cache); return cache; }
@Test public void testOnReset() throws Exception { Supplier<String> supplier = mock(Supplier.class); when(supplier.get()).thenReturn("RESET"); CachedReference<String> reference = factory.getCachedReference("reset", supplier, settingsBuilder().build()); CachedReferenceListener listener = mock(CachedReferenceListener.class); reference.addListener(listener, true); reference.get(); reference.reset(); ArgumentCaptor<CachedReferenceEvent> captor = ArgumentCaptor.forClass(CachedReferenceEvent.class); //With the changes to the delegated memory reset / remove there will be another call on the //listener when this test is run as part of the suite verify(listener, timeout(1000).atLeastOnce()).onReset(captor.capture()); CachedReferenceEvent<String> event = captor.getValue(); assertEquals("RESET", event.getValue()); }
protected Cache<String, Long> makeStatisticsEnabledCache() { final Cache<String, Long> cache = factory.getCache("mycache", null, statsEnabledSettings); assertEmpty(cache); return cache; }
@Test public void testOnEvict() throws Exception { Supplier<String> supplier = mock(Supplier.class); when(supplier.get()).thenReturn("EVICT"); CachedReference<String> reference = factory.getCachedReference("evict", supplier, settingsBuilder().expireAfterAccess(1, TimeUnit.SECONDS).expireAfterWrite(1, TimeUnit.SECONDS).build()); CachedReferenceListener listener = mock(CachedReferenceListener.class); reference.addListener(listener, true); reference.get(); Thread.sleep(EXPIRY_TIMEOUT); reference.get(); ArgumentCaptor<CachedReferenceEvent> captor = ArgumentCaptor.forClass(CachedReferenceEvent.class); verify(listener, timeout(EXPIRY_TIMEOUT).atLeastOnce()).onEvict(captor.capture()); CachedReferenceEvent<String> event = captor.getValue(); assertEquals("EVICT", event.getValue()); }
private GenericCacheWrapper<String, List<String>> getCache() { return new GenericCacheWrapper<String, List<String>>( cacheFactory.getCache(cacheName)); }
@Test public void testFactoryGeneratedName() throws Exception { CachedReference<Long> ref = factory.getCachedReference( Object.class, "mycache", nullSupplier(), settingsBuilder().build()); assertThat(((ManagedCache)ref).getName(), equalTo("java.lang.Object.mycache")); }