io.quarkus.cache.runtime.CaffeineCacheSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-cache Show documentation
Show all versions of quarkus-cache Show documentation
Enable application data caching in CDI beans
package io.quarkus.cache.runtime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import io.quarkus.arc.Arc;
import io.quarkus.cache.Cache;
import io.quarkus.cache.CacheManager;
import io.quarkus.cache.CaffeineCache;
public class CaffeineCacheSupplier implements Supplier> {
@Override
public List get() {
CacheManager cacheManager = cacheManager();
Collection names = cacheManager.getCacheNames();
List allCaches = new ArrayList<>(names.size());
for (String name : names) {
Optional cache = cacheManager.getCache(name);
if (cache.isPresent() && cache.get() instanceof CaffeineCache) {
allCaches.add((CaffeineCache) cache.get());
}
}
allCaches.sort(Comparator.comparing(CaffeineCache::getName));
return allCaches;
}
public static CacheManager cacheManager() {
return Arc.container().instance(CacheManager.class).get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy