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 * Return 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 this case a reasonable 037 * default can be assumed for the expiry, the cache will use the 038 * configured expiry time. 039 * 040 * @param _oldObject the value currently in the cache. null if it is not 041 * in the cache, is a null value (null is supported for values) 042 * or the previous fetch operation yielded in an exception. 043 * @param _timeOfLastRefresh time of the last cache refresh, a put or a fetch 044 * from the cache source. 045 * @param _newObject the value which will be put in the cache. 046 * @param now this is the current time in millis. If a cache source was used to 047 * fetch the value, this is the time before the fetch was started. 048 * @return time of next refresh in millis. 0 if it should not be cached at all. 049 */ 050 public abstract long calculateNextRefreshTime( 051 T _oldObject, 052 T _newObject, 053 long _timeOfLastRefresh, 054 long now); 055 056}