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

de.otto.edison.cache.controller.CacheInfo Maven / Gradle / Ivy

package de.otto.edison.cache.controller;

import de.otto.edison.annotations.Beta;
import de.otto.edison.cache.configuration.GuavaCacheConfig;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Statistics and specification of configured Guava caches.
 *
 * @since 0.51.0
 *
 * @deprecated since 0.76.0, use edison-cache instead
 */
@Beta
@Deprecated
public final class CacheInfo {

    private final String name;
    private final Map metrics = new LinkedHashMap<>();
    private final Map specification = new LinkedHashMap<>();

    /**
     * Creates a CacheInfo object for the specified cache.
     *
     * @param cacheName the name of the cache as specified in {@link GuavaCacheConfig}.
     */
    public CacheInfo(final String cacheName) {
        this.name = cacheName;
    }

    /**
     * Returns the name of the cache.
     *
     * @return the name of the cache as specified in {@link GuavaCacheConfig}.
     */
    public String getName() {
        return name;
    }

    /**
     * Sets a single metric value.
     *
     * @param key the key of the metric
     * @param value the metric's value
     */
    void setMetric(final String key, final Number value) {
        metrics.put(key, value);
    }

    /**
     * Returns the Map of metrics.
     *
     * @return Current values of the cache metrics.
     */
    public Map getMetrics() {
        return metrics;
    }

    /**
     * Sets the cache specification containing information about expiration etc.
     *
     * @param spec Cache specification
     */
    void setSpecification(final Map spec) {
        this.specification.putAll(spec);
    }

    /**
     * Returns the cache specification properties.
     *
     * @return Cache specification
     */
    public Map getSpecification() {
        return specification;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CacheInfo cacheInfo = (CacheInfo) o;

        if (name != null ? !name.equals(cacheInfo.name) : cacheInfo.name != null) return false;
        if (metrics != null ? !metrics.equals(cacheInfo.metrics) : cacheInfo.metrics != null) return false;
        return !(specification != null ? !specification.equals(cacheInfo.specification) : cacheInfo.specification != null);

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (metrics != null ? metrics.hashCode() : 0);
        result = 31 * result + (specification != null ? specification.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "CacheInfo{" +
                "name='" + name + '\'' +
                ", metrics=" + metrics +
                ", specification=" + specification +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy