View Javadoc

1   package com.atlassian.cache;
2   
3   import javax.annotation.Nonnull;
4   
5   import com.atlassian.annotations.PublicSpi;
6   
7   /**
8    * Populates a cache, for example lazily upon a miss.
9    *
10   * @param <K> the type of key used by the cache
11   * @param <V> the type of value stored in the cache
12   * @since 2.0
13   */
14  @PublicSpi
15  public interface CacheLoader<K, V>
16  {
17      /**
18       * Loads the value for the given key.
19       *
20       * @param key the key for which to load the value (required)
21       * @return a non-null value; if null values are possible, e.g. when the key is a database ID that does not
22       * actually exist, declare the loader's value type to be a wrapper type such as Guava's {@code Option<Foo>} class
23       */
24      @Nonnull
25      V load(@Nonnull K key);
26  }