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

org.opensearch.common.cache.ICache Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 */

package org.opensearch.common.cache;

import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.common.cache.stats.ImmutableCacheStatsHolder;
import org.opensearch.common.cache.store.config.CacheConfig;

import java.io.Closeable;
import java.util.Map;

/**
 * Represents a cache interface.
 * @param  Type of key.
 * @param  Type of value.
 *
 * @opensearch.experimental
 */
@ExperimentalApi
public interface ICache extends Closeable {
    V get(ICacheKey key);

    void put(ICacheKey key, V value);

    V computeIfAbsent(ICacheKey key, LoadAwareCacheLoader, V> loader) throws Exception;

    /**
     * Invalidates the key. If a dimension in the key has dropStatsOnInvalidation set to true, the cache also completely
     * resets stats for that dimension value. It's the caller's responsibility to make sure all keys with that dimension value are
     * actually invalidated.
     */
    void invalidate(ICacheKey key);

    void invalidateAll();

    Iterable> keys();

    long count();

    void refresh();

    // Return total stats only
    default ImmutableCacheStatsHolder stats() {
        return stats(null);
    }

    // Return stats aggregated by the provided levels. If levels is null or an empty array, return total stats only.
    ImmutableCacheStatsHolder stats(String[] levels);

    /**
     * Factory to create objects.
     */
    @ExperimentalApi
    interface Factory {
         ICache create(CacheConfig config, CacheType cacheType, Map cacheFactories);

        String getCacheName();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy