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

org.duracloud.common.cache.AbstractAccountComponentCache Maven / Gradle / Ivy

There is a newer version: 8.1.0
Show newest version
/*
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */
package org.duracloud.common.cache;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author Daniel Bernstein
 *
 * @param 
 */
public abstract class AbstractAccountComponentCache implements AccountComponentCache {
    private Map cache;

    public AbstractAccountComponentCache() {
        this.cache = new HashMap<>();
    }

    protected void remove(String key) {
        this.cache.remove(key);
    }

    protected void removeAll() {
        this.cache.clear();
    }

    @Override
    public T get(String accountId) {
        T instance = this.cache.get(accountId);
        if (instance == null) {
            instance = createInstance(accountId);
            this.cache.put(accountId, instance);
        }

        return instance;
    }

    protected abstract T createInstance(String accountId);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy