001package org.cache2k;
002
003/*
004 * #%L
005 * cache2k API only package
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
023/**
024 * Calculates the time when the object needs to be updated next.
025 * 
026 * @author Jens Wilke; created: 2010-06-24
027 */
028public abstract interface RefreshController<T> {
029
030  /**
031   * Returns the time of next refresh (expiry time) in milliseconds since epoch.
032   * If 0 is returned, this means entry expires immediately, or is always
033   * fetched from the source. If {@link Long#MAX_VALUE} is returned it means
034   * there is no specific expiry time known or needed. In case a reasonable
035   * default can be assumed for the expiry, the cache will use the
036   * configured expiry time.
037   *
038   * <p>The cache may call the method a second (or more) times, if the
039   * expiry time needs a recalculation. The reason for this is to react on
040   * possible configuration changes properly. This may happen when an entry
041   * is read back from storage.
042   *
043   * @param _oldObject the value currently in the cache. null if it is not
044   *                   in the cache, is a null value (null is supported for values)
045   *                   or the previous fetch operation yielded in an exception.
046   * @param _timeOfLastRefresh time of the last cache refresh, by put or from the cache source.
047   * @param _newObject the value which will be put in the cache.
048   * @param _fetchTime this is the current time in millis. If a cache source was used to
049   *            fetch the value, this is the time before the fetch was started.
050   * @return time of next refresh in millis. 0 if it should not be cached at all.
051   */
052  public abstract long calculateNextRefreshTime(
053    T _oldObject,
054    T _newObject,
055    long _timeOfLastRefresh,
056    long _fetchTime);
057
058}