org.cache2k.integration.AdvancedCacheLoader Maven / Gradle / Ivy
Show all versions of cache2k-api Show documentation
package org.cache2k.integration;
/*
* #%L
* cache2k API
* %%
* Copyright (C) 2000 - 2016 headissue GmbH, Munich
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.cache2k.Cache2kBuilder;
import org.cache2k.CacheEntry;
/**
* Retrieves or generates a value to load into the cache. The advanced loader interface
* contains the current time and the previous cache entry. The previous cache entry
* can be used for a more intelligent loading strategy, e.g. for HTTP based loading with
* the If-Modified-Since
header.
*
* For general documentation on the loader, please see {@link CacheLoader}.
*
* @author Jens Wilke
* @see CacheLoader
* @since 0.24
*/
public abstract class AdvancedCacheLoader {
/**
* Retrieves or generates data based on the key.
*
* @param key The non-null key to provide the value for.
* @param currentTime Time in millis, retrieved before the call.
* @param currentEntry entry currently in the cache, regardless whether expired or not.
* There is no guarantee that an expired entry will be provided to the loader.
* Depending und passed time and configuration expired entries may be purged from
* the cache before the next load happens. Check the configuration parameters
* {@link Cache2kBuilder#keepDataAfterExpired(boolean)} and
* {@link Cache2kBuilder#refreshAhead(boolean)}.
* @return value to be associated with the key. If the cache permits null values
* a null is associated with the key.
* @throws Exception Unhandled exception from the loader. Exceptions are suppressed or
* wrapped and rethrown via a {@link CacheLoaderException}
*/
public abstract V load(K key, long currentTime, CacheEntry currentEntry) throws Exception;
}