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

io.quarkus.cache.runtime.noop.NoOpCacheManagerBuilder Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.cache.runtime.noop;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;

import io.quarkus.cache.Cache;
import io.quarkus.cache.CacheManager;
import io.quarkus.cache.runtime.CacheManagerImpl;

public class NoOpCacheManagerBuilder {

    public static Supplier build(Set cacheNames) {
        Objects.requireNonNull(cacheNames);
        return new Supplier() {
            @Override
            public CacheManager get() {
                if (cacheNames.isEmpty()) {
                    return new CacheManagerImpl(Collections.emptyMap());
                } else {
                    // The number of caches is known at build time so we can use fixed initialCapacity and loadFactor for the caches map.
                    Map caches = new HashMap<>(cacheNames.size() + 1, 1.0F);
                    NoOpCache cache = new NoOpCache();
                    for (String cacheName : cacheNames) {
                        caches.put(cacheName, cache);
                    }
                    return new CacheManagerImpl(caches);
                }
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy