001package org.cache2k;
002
003/*
004 * #%L
005 * cache2k API only package
006 * %%
007 * Copyright (C) 2000 - 2014 headissue GmbH, Munich
008 * %%
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as
011 * published by the Free Software Foundation, either version 3 of the 
012 * License, or (at your option) any later version.
013 * 
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 * 
019 * You should have received a copy of the GNU General Public 
020 * License along with this program.  If not, see
021 * <http://www.gnu.org/licenses/gpl-3.0.html>.
022 * #L%
023 */
024
025/**
026 * Calculates the time when the object needs to be updated next.
027 * 
028 * @author Jens Wilke; created: 2010-06-24
029 */
030public abstract interface RefreshController<T> {
031
032  /**
033   * Returns the time of next refresh (expiry time) in milliseconds since epoch.
034   * If 0 is returned, this means entry expires immediately, or is always
035   * fetched from the source. If {@link Long#MAX_VALUE} is returned it means
036   * there is no specific expiry time known or needed. In case a reasonable
037   * default can be assumed for the expiry, the cache will use the
038   * configured expiry time.
039   *
040   * <p>The cache may call the method a second (or more) times, if the
041   * expiry time needs a recalculation. The reason for this is to react on
042   * possible configuration changes properly. This may happen when an entry
043   * is read back from storage.
044   *
045   * @param _oldObject the value currently in the cache. null if it is not
046   *                   in the cache, is a null value (null is supported for values)
047   *                   or the previous fetch operation yielded in an exception.
048   * @param _timeOfLastRefresh time of the last cache refresh, by put or from the cache source.
049   * @param _newObject the value which will be put in the cache.
050   * @param _fetchTime this is the current time in millis. If a cache source was used to
051   *            fetch the value, this is the time before the fetch was started.
052   * @return time of next refresh in millis. 0 if it should not be cached at all.
053   */
054  public abstract long calculateNextRefreshTime(
055    T _oldObject,
056    T _newObject,
057    long _timeOfLastRefresh,
058    long _fetchTime);
059
060}