001/* 002 * JKNIV, utils - Helper utilities for jdk code. 003 * 004 * Copyright (C) 2017, the original author or authors. 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software Foundation, Inc., 018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 019 */ 020package net.sf.jkniv.cache; 021 022import java.util.concurrent.TimeUnit; 023 024/* 025 026 no expiry - this means cache mappings will never expire, 027 time-to-live - this means cache mappings will expire after a fixed duration following their creation, 028 time-to-idle - this means cache mappings will expire after a fixed duration following the time they were last accessed. 029 030 */ 031/** 032 * Cache keep the objects with a {@code Policy} to indicate if continue alive. 033 * 034 * @author Alisson Gomes 035 * @since 0.6.0 036 */ 037public interface CachePolicy 038{ 039 static final long DEFAULT_TTL = 60; 040 static final long DEFAULT_TTI = -1; 041 static final long DEFAULT_SIZE = 1000; 042 static final long DEFAULT_INITIALDELAY = TimeUnit.MINUTES.toSeconds(10L); 043 static final long DEFAULT_PERIOD = TimeUnit.MINUTES.toSeconds(5L); 044 static final long DEFAULT_SIZEOF = -1; 045 046 /** 047 * Verify if cache is live indicating to discard the cache content. 048 * @param miliseconds time from object stored 049 * @return <b>true</b> when object is alive, <b>false</b> otherwise 050 */ 051 boolean isAlive(long miliseconds); 052 053 /** 054 * Verify if cache is live indicating to discard the cache content. 055 * @param ttl time-to-live from stored object in seconds 056 * @param tti time-to-idle for stored store in seconds 057 * @return <b>true</b> when object is alive, <b>false</b> otherwise 058 */ 059 boolean isAlive(long ttl, long tti); 060 061 /** 062 * Returns the number of elements in cache. 063 * @return the number of elements in cache. 064 */ 065 long size(); 066 067 /** 068 * Returns the limit size of objects in cache. 069 * @return the limit size of objects in cache. 070 */ 071 long sizeof(); 072}