/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.cache;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* A cache implementation that maintains items up to a threshold size. If the threshold size is reached
* it begins removing old items during get() calls as they time-out after a specified timeout value.
*
* If the threshold value is not reached, the items are not removed unless specifically requested with
* a call to remove() or clear().
*
* If the max size value is reached then no more items are added to the cache until some are removed
* either explicitly or automically via timed-out values.
*
* @author Kevin Roast
*/
public class AutoExpireCache implements SimpleCache
{
// TODO: configure these values via Spring
private final long TIMEDIFF = 1000000L * 1000L * 60L * 5L; // 5 mins in nano-seconds
private final int MAXSIZE = 4096; // maximum size of the cache
private final float THRESHOLD = 0.75f; // before we start removing items
private int maxsize = MAXSIZE;
private float threshold = THRESHOLD;
private Map