001package org.cache2k.integration;
002
003/*
004 * #%L
005 * cache2k API
006 * %%
007 * Copyright (C) 2000 - 2016 headissue GmbH, Munich
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import org.cache2k.Cache2kBuilder;
024import org.cache2k.CacheEntry;
025
026/**
027 * Retrieves or generates a value to load into the cache. The advanced loader interface
028 * contains the current time and the previous cache entry. The previous cache entry
029 * can be used for a more intelligent loading strategy, e.g. for HTTP based loading with
030 * the <code>If-Modified-Since</code> header.
031 *
032 * <p>For general documentation on the loader, please see {@link CacheLoader}.
033 *
034 * @author Jens Wilke
035 * @see CacheLoader
036 * @since 0.24
037 */
038public abstract class AdvancedCacheLoader<K,V> {
039
040  /**
041   * Retrieves or generates data based on the key.
042   *
043   * @param key The non-null key to provide the value for.
044   * @param currentTime Time in millis, retrieved before the call.
045   * @param currentEntry entry currently in the cache, regardless whether expired or not.
046   *                     There is no guarantee that an expired entry will be provided to the loader.
047   *                     Depending und passed time and configuration expired entries may be purged from
048   *                      the cache before the next load happens. Check the configuration parameters
049   *                      {@link Cache2kBuilder#keepDataAfterExpired(boolean)} and
050   *                      {@link Cache2kBuilder#refreshAhead(boolean)}.
051   * @return value to be associated with the key. If the cache permits null values
052   *         a null is associated with the key.
053   * @throws Exception Unhandled exception from the loader. Exceptions are suppressed or
054   *                   wrapped and rethrown via a {@link CacheLoaderException}
055   */
056  public abstract V load(K key, long currentTime, CacheEntry<K,V> currentEntry) throws Exception;
057
058}