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

org.apache.james.mailbox.caching.guava.GuavaMailboxByPathCache 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.MailboxByPathCache;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.mail.MailboxMapper;
import org.apache.james.mailbox.store.mail.model.Mailbox;

import com.google.common.cache.Cache;

/**
 * Guava-based implementation of MailboxByPathCache.
 * Note: for efficiency/simplicity reasons the cache key is MailboxPath.toString()
 * That may help also make it compatible with other cache backends in the future.
 *
 */
public class GuavaMailboxByPathCache extends AbstractGuavaCache implements MailboxByPathCache {

    private final Cache findMailboxByPathCache = BUILDER.build();

    private final MailboxByPathCacheWrapper wrapper;


    public GuavaMailboxByPathCache() {
        this.wrapper = new MailboxByPathCacheWrapper(findMailboxByPathCache);
    }

    @Override
    public Mailbox findMailboxByPath(MailboxPath mailboxName, MailboxMapper underlying) throws MailboxNotFoundException, MailboxException {

        return wrapper.get(mailboxName, underlying);
    }

    @Override
    public void invalidate(Mailbox mailbox) {
        invalidate(mailbox.generateAssociatedPath());
    }

    @Override
    public void invalidate(MailboxPath mailboxPath) {
        wrapper.invalidate(mailboxPath);
    }

    class MailboxByPathCacheWrapper extends GuavaCacheWrapper {

        public MailboxByPathCacheWrapper(
                Cache cache/*,
                MailboxByPathCacheLoaderFromUnderlying loader*/) {
            super(cache);
        }

        @Override
        public Mailbox load(MailboxPath mailboxName, MailboxMapper underlying) throws MailboxException {
            return underlying.findMailboxByPath(mailboxName);
        }

        @Override
        public String getKeyRepresentation(MailboxPath key) {
            return key.toString();
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy