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

csip.utils.SimpleCache Maven / Gradle / Ivy

Go to download

The Cloud Services Integration Platform is a SoA implementation to offer a Model-as-a-Service framework, Application Programming Interface, deployment infrastructure, and service implementations for environmental modeling.

There is a newer version: 2.6.30
Show newest version
/*
 * $Id: SimpleCache.java c4b9d8c126c7 2020-07-28 [email protected] $
 *
 * This file is part of the Cloud Services Integration Platform (CSIP),
 * a Model-as-a-Service framework, API and application suite.
 *
 * 2012-2019, Olaf David and others, OMSLab, Colorado State University.
 *
 * OMSLab licenses this file to you under the MIT license.
 * See the LICENSE file in the project root for more information.
 */
package csip.utils;

import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

/**
 * Simple, non-evicting cache. Good for Resource caching.
 *
 * @author od
 * @param  generic key
 * @param  generic value
 */
public class SimpleCache extends ConcurrentHashMap {

  private static final long serialVersionUID = 1L;


  /**
   * Get the cache entry. If not present, the Function f will be invoked to
   * create one.
   *
   * @param k the key
   * @param f the Function to create the value
   * @return the cache value
   */
  public synchronized V get(K k, Function f) {
    V v = get(k);
    if (v == null && f != null) {
      put(k, v = f.apply(k));
    }
    return v;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy