All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jodd.cache.Cache Maven / Gradle / Ivy

Go to download

Jodd Core tools and utilities, including type converters, JDateTime, cache etc.

There is a newer version: 5.3.0
Show newest version
// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.cache;

import java.util.Iterator;

/**
 * Cache interface.
 */
public interface Cache {

	/**
	 * Returns cache size or 0 if there is no size limit.
	 */
	int getCacheSize();

	/**
	 * Returns default timeout or 0 if it is not set.
	 */
	long getCacheTimeout();

	/**
	 * Adds an object to the cache with default timeout.
	 * @see Cache#put(Object, Object, long)
	 */
	void put(K key, V object);

	/**
	 * Adds an object to the cache with specified timeout after which it becomes expired.
	 * If cache is full, {@link #prune()} is invoked to make room for new object.
	 */
	void put(K key, V object, long timeout);

	/**
	 * Retrieves an object from the cache. Returns null if object
	 * is not longer in cache or if it is expired.
	 */
	V get(K key);

	/**
	 * Returns iterator over non-expired values.
	 */
	Iterator iterator();

	/**
	 * Prunes objects from cache and returns the number of removed objects.
	 * Used strategy depends on cache implementation.
	 */
	int prune();

	/**
	 * Returns true if max cache capacity has been reached
	 * only if cache is size limited.
	 */
	boolean isFull();

	/**
	 * Removes an object from the cache.
	 */
	void remove(K key);

	/**
	 * Clears current cache.
	 */
	void clear();

	/**
	 * Returns current cache size.
	 */
	int size();

	/**
	 * Returns true if cache is empty.
	 */
	boolean isEmpty();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy