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
025import javax.annotation.Nonnull;
026import javax.annotation.Nullable;
027
028/**
029 * Calculates the time when the object needs to be updated next.
030 * 
031 * @author Jens Wilke; created: 2010-06-24
032 */
033public abstract interface RefreshController<T> {
034
035  /**
036   * Return time of next refresh (expiry time) in milliseconds since epoch.
037   * If 0 is returned, this means entry expires immediately, or is always
038   * fetched from the source. If {@link Long#MAX_VALUE} is returned it means
039   * there is no specific expiry time known or needed. In this case a reasonable
040   * default can be assumed for the expiry, the cache will use the
041   * configured expiry time.
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, a put or a fetch
047   *                           from the cache source.
048   * @param _newObject the value which will be put in the cache.
049   * @param now this is the current time in millis. If a cache source was used to
050   *            fetch the value, this is the time before the fetch was started.
051   * @return time of next refresh in millis. 0 if it should not be cached at all.
052   */
053  public abstract long calculateNextRefreshTime(
054    @Nullable T _oldObject,
055    @Nonnull T _newObject,
056    long _timeOfLastRefresh,
057    long now);
058
059}