public DefaultSecureUserTokenManager(final CacheManager cacheManager) { tokenCache = cacheManager.getCache(DefaultSecureUserTokenManager.class.getName() + ".tokenCache", null, new CacheSettingsBuilder().expireAfterAccess(30, TimeUnit.MINUTES).build()); }
@Test public void testBothExpireHintsSpecified() { CacheSettings required = new CacheSettingsBuilder() .expireAfterAccess(60, TimeUnit.SECONDS) .expireAfterWrite(30, TimeUnit.SECONDS) .build(); Cache<String, String> cache = factory.getCache("fruity", null, required); assertThat(cache, not(nullValue())); } }
CachingUserHistoryStore(@Nonnull final OfBizUserHistoryStore delegatingStore, @Nonnull final ApplicationProperties applicationProperties, final CacheManager cacheManager, int maxThreshold) { this.delegatingStore = notNull("delegatingStore", delegatingStore); this.applicationProperties = notNull("applicationProperties", applicationProperties); this.maxThreshold = maxThreshold; this.cache = cacheManager.getCache(CachingUserHistoryStore.class.getName() + ".cache", new DelegatingStoreCacheLoader(), new CacheSettingsBuilder().local().expireAfterAccess(15, TimeUnit.MINUTES).build()); }
private static CacheSettings newCacheSettings() throws InvocationTargetException, IllegalAccessException { return new CacheSettingsBuilder() .replicateViaInvalidation() .expireAfterWrite(DEFAULT_CACHE_EXPIRY_IN_SECONDS, TimeUnit.SECONDS) .build(); }
private CacheSettings asSerializable(CacheSettings settings) { if (settings instanceof Serializable) { return settings; } // DefaultCacheSettings implements Serializable, make a copy return new CacheSettingsBuilder(settings).build(); }
public ClusterMonitoredTaskExecutor(CacheFactory cacheFactory, String name, int maxThreads) { super(name, maxThreads); clusterMonitors = cacheFactory.getCache(TASK_MONITOR_PREFIX + name, null, new CacheSettingsBuilder() // entries should be removed when the local monitor expires, but let's be paranoid .expireAfterWrite(2, TimeUnit.HOURS) .remote() .build()); }
public LazyOfBizUserCache(final CacheManager cacheManager, final OfBizDelegator ofBizDelegator) { this.ofBizDelegator = ofBizDelegator; this.cache = cacheManager.getCache(LazyOfBizUserCache.class.getName() + ".userCache", new UserCacheLoader(), new CacheSettingsBuilder() .expireAfterAccess(30, TimeUnit.MINUTES).flushable().build()); }
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()); }
protected <V> CachedReference<V> createDistributedCachedReference(String name, Supplier<V> supplier, CacheSettings settings) { // override the settings to ensure the reference is flushable and the max is set to 1000. A low value for // maxEntries would trigger continuous cache invalidations because of the way map eviction works in Hazelcast. final CacheSettings overriddenSettings = checkNotNull(settings, "settings").override( new CacheSettingsBuilder().flushable().maxEntries(1000).build()); final String mapName = PREFIX_CACHE_REFERENCE + name; configureMap(mapName, overriddenSettings); final IMap<String, OsgiSafe<V>> map = hazelcast.getMap(mapName); return new HazelcastCachedReference<V>(name, map, supplier, this); }
public ClusterLogScanCache(CacheManager cacheManager) { lastScan = cacheManager.getCache("com.atlassian.stp.lastLogScan", null, new CacheSettingsBuilder() .expireAfterWrite(CACHE_EXPIRY_DURATION_MS, TimeUnit.MILLISECONDS) .local() .build()); }
@Autowired public DefaultRemoteCapabilitiesService(ApplicationLinkService applicationLinkService, ApplinkHelper applinkHelper, ApplinksRequestCache applinksRequestCache, EventPublisher eventPublisher, AppLinksManifestDownloader manifestDownloader, PermissionValidationService permissionValidationService, ServiceExceptionFactory serviceExceptionFactory, CacheFactory cacheFactory) { this.applicationLinkService = applicationLinkService; this.applinkHelper = applinkHelper; this.applinksRequestCache = applinksRequestCache; this.eventPublisher = eventPublisher; this.manifestDownloader = manifestDownloader; this.permissionValidationService = permissionValidationService; this.serviceExceptionFactory = serviceExceptionFactory; this.capabilitiesCache = cacheFactory.getCache("applinks.capabilities", null, new CacheSettingsBuilder() .local() .maxEntries(MAX_CACHE_SIZE) .build()); }
@Override public boolean updateMaxEntries(int newValue) { CacheSettings newCacheSettings = new CacheSettingsBuilder(getCacheSettings()).maxEntries(newValue).build(); return cacheManager.updateCacheSettings(getHazelcastMapName(), newCacheSettings); }
private Cache<String, Boolean> getSettingsCache(CacheManager cacheManager) { // Use a <String, Boolean> Cache instead of a <Key, Boolean> cache to prevent classloader issues (at least in // Bitbucket Server) CacheLoader<String, Boolean> cacheLoader = new CacheLoader<String, Boolean>() { @Override public Boolean load(@Nonnull String key) { return getBooleanSetting(Key.valueOf(key)); } }; CacheSettings cacheSettings = new CacheSettingsBuilder(). remote(). replicateAsynchronously(). replicateViaInvalidation(). build(); return cacheManager.getCache(CACHE_KEY, cacheLoader, cacheSettings); }
TokenManagerImpl(final long timeout, final PermissionManager permissionManager, final LoginService loginService, final JiraAuthenticationContext authenticationContext, final UserManager userManager, final CacheManager cacheManager) { this.permissionManager = permissionManager; this.loginService = loginService; this.authenticationContext = authenticationContext; this.userManager = userManager; userTokens = cacheManager.getCache(TokenManagerImpl.class.getName() + ".userCache", null, new CacheSettingsBuilder().replicateViaCopy().expireAfterAccess(timeout, TimeUnit.MILLISECONDS).build()); }
protected CacheSettingsBuilder settingsBuilder(boolean statsEnabled) { final CacheSettingsBuilder bob = new CacheSettingsBuilder(); if (statsEnabled) { bob.statisticsEnabled(); } else { bob.statisticsDisabled(); } if (cacheType == CacheType.LOCAL) { bob.local(); } else if (cacheType == CacheType.REMOTE) { bob.remote(); } else if (cacheType == CacheType.HYBRID) { bob.remote().replicateViaInvalidation(); } return bob; }
@Nonnull @Override public CacheSettings getDefaults(@Nonnull final String cacheName) { CacheSettingsBuilder cacheSettingsBuilder = new CacheSettingsBuilder(); if (enableStatistics) { return cacheSettingsBuilder.statisticsEnabled().build(); } else { return cacheSettingsBuilder.statisticsDisabled().build(); } } }
@Override public boolean updateExpireAfterWrite(long expireAfter, TimeUnit timeUnit) { CacheSettings newCacheSettings = new CacheSettingsBuilder(getCacheSettings()).expireAfterWrite(expireAfter, timeUnit).build(); return cacheManager.updateCacheSettings(getHazelcastMapName(), newCacheSettings); }
@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()); }
settings.override(new CacheSettingsBuilder().flushable().build()));
protected Cache<String, Long> makeSizeLimitedCache(int maxEntries) { CacheSettings required = settingsBuilder().maxEntries(maxEntries).build(); final Cache<String, Long> cache = factory.getCache("mycache", null, required); assertEmpty(cache); return cache; }