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