All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.cache.runtime.CaffeineCacheSupplier Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
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