com.github.benmanes.caffeine.cache.Scheduler Java Examples
The following examples show how to use
com.github.benmanes.caffeine.cache.Scheduler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpiringAfterWriteCache.java From triplea with GNU General Public License v3.0 | 6 votes |
@Builder public ExpiringAfterWriteCache( final long duration, final TimeUnit timeUnit, final BiConsumer<IdT, ValueT> removalListener) { cache = Caffeine.newBuilder() .expireAfterWrite(duration, timeUnit) .scheduler(Scheduler.systemScheduler()) .removalListener( (IdT key, ValueT value, RemovalCause cause) -> { if (cause == RemovalCause.EXPIRED || cause == RemovalCause.EXPLICIT) { removalListener.accept(key, value); } }) .build(); this.removalListener = removalListener; }
Example #2
Source File: CFAccessorCacheCaffeine.java From promregator with Apache License 2.0 | 4 votes |
@PostConstruct public void setupCaches() { log.info(String.format("Cache refresh timings: org cache: %ds, space cache: %ds, app cache: %ds, app summary cache: %ds", this.refreshCacheOrgLevelInSeconds, this.refreshCacheSpaceLevelInSeconds, this.refreshCacheApplicationLevelInSeconds, this.refreshCacheApplicationLevelInSeconds)); log.info(String.format("Cache expiry timings: org cache: %ds, space cache: %ds, app cache: %ds, app summary cache: %ds", this.expiryCacheOrgLevelInSeconds, this.expiryCacheSpaceLevelInSeconds, this.expiryCacheApplicationLevelInSeconds, this.expiryCacheApplicationLevelInSeconds)); Scheduler caffeineScheduler = Scheduler.forScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); this.orgCache = Caffeine.newBuilder() .expireAfterAccess(this.expiryCacheOrgLevelInSeconds, TimeUnit.SECONDS) .refreshAfterWrite(this.refreshCacheOrgLevelInSeconds, TimeUnit.SECONDS) .scheduler(caffeineScheduler) .recordStats() .buildAsync(new OrgCacheLoader()); this.internalMetrics.addCaffeineCache("orgCache", this.orgCache); this.allOrgIdCache = Caffeine.newBuilder() .expireAfterAccess(this.expiryCacheOrgLevelInSeconds, TimeUnit.SECONDS) .refreshAfterWrite(this.refreshCacheOrgLevelInSeconds, TimeUnit.SECONDS) .recordStats() .scheduler(caffeineScheduler) .buildAsync(new AllOrgIdCacheLoader()); this.internalMetrics.addCaffeineCache("allOrgCache", this.allOrgIdCache); this.spaceCache = Caffeine.newBuilder() .expireAfterAccess(this.expiryCacheSpaceLevelInSeconds, TimeUnit.SECONDS) .refreshAfterWrite(this.refreshCacheSpaceLevelInSeconds, TimeUnit.SECONDS) .recordStats() .scheduler(caffeineScheduler) .buildAsync(new SpaceCacheLoader()); this.internalMetrics.addCaffeineCache("spaceCache", this.spaceCache); this.spaceIdInOrgCache = Caffeine.newBuilder() .expireAfterAccess(this.expiryCacheSpaceLevelInSeconds, TimeUnit.SECONDS) .refreshAfterWrite(this.refreshCacheSpaceLevelInSeconds, TimeUnit.SECONDS) .recordStats() .scheduler(caffeineScheduler) .buildAsync(new SpaceIdInOrgCacheLoader()); this.internalMetrics.addCaffeineCache("spaceInOrgCache", this.spaceIdInOrgCache); this.appsInSpaceCache = Caffeine.newBuilder() .expireAfterAccess(this.expiryCacheApplicationLevelInSeconds, TimeUnit.SECONDS) .refreshAfterWrite(this.refreshCacheApplicationLevelInSeconds, TimeUnit.SECONDS) .recordStats() .scheduler(caffeineScheduler) .buildAsync(new AppsInSpaceCacheLoader()); this.internalMetrics.addCaffeineCache("appsInSpace", this.appsInSpaceCache); this.spaceSummaryCache = Caffeine.newBuilder() .expireAfterAccess(this.expiryCacheApplicationLevelInSeconds, TimeUnit.SECONDS) .refreshAfterWrite(this.refreshCacheApplicationLevelInSeconds, TimeUnit.SECONDS) .recordStats() .scheduler(caffeineScheduler) .buildAsync(new SpaceSummaryCacheLoader()); this.internalMetrics.addCaffeineCache("spaceSummary", this.spaceSummaryCache); }
Example #3
Source File: CacheContext.java From caffeine with Apache License 2.0 | 4 votes |
public Scheduler scheduler() { return scheduler; }