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

org.apache.james.mailbox.caching.guava.GuavaCacheWrapper Maven / Gradle / Ivy

Go to download

JAMES-2703 This maven module is deprecated and will be removed straight after upcoming James 3.4.0 release, unless it finds a maintainer. This module lacks tests and is not used in James products hence the choice to deprecate it.

There is a newer version: 3.4.0
Show newest version
package org.apache.james.mailbox.caching.guava;

import org.apache.james.mailbox.caching.CacheLoaderFromUnderlying;

import com.google.common.cache.Cache;

public abstract class GuavaCacheWrapper
    implements CacheLoaderFromUnderlying {

    private final Cache cache;

    public GuavaCacheWrapper(Cache cache/*, CacheLoaderFromUnderlying loader*/) {
        this.cache = cache;
    }

    public ValueT get(KeyT key, UnderlyingT underlying) throws ExceptT {
        ValueT value = cache.getIfPresent(getKeyRepresentation(key));
        if (value != null) {
            return value;
        } else {
            value = load(key, underlying);
            if (value != null) {
                cache.put(getKeyRepresentation(key), value);
            }
            return value;
        }

    }

    public void invalidate(KeyT key) {
        if (key != null) { //needed?
            cache.invalidate(getKeyRepresentation(key));
        }
    }

    public abstract KeyRepresentationT getKeyRepresentation(KeyT key);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy