Introduction
Guit 1.5 will include a cache system for your actions. This document describes how it will work.
Details
There is a new interface: Cacheable. It looks like:
/**
* Implement in an action to make it cacheable.
* IMPORTANT: Must override hashCode and equals to work properly
*/
public interface Cacheable {
/**
* @return The expiration time in ms.
*/
int getExpirationTime();
}If you implement this interface to an action it will get cached. You must override equals and hashCode, they will be used to indentify a unique action.
A cached action will expire after the interval returned from getExpirationTime(). If you return 0 it will be cached forever.
Programmatically remove cache
The CommandManager have two new methods to achieve this goal:
/**
* Remove all cache actions of a specific class.
* @param <A> Action
* @param actionClass Class
*/
@SuppressWarnings("rawtypes")
<A extends Action> void clearCache(Class<A> actionClass);
/**
* Remove a specific cached action.
* @param <A> Action
* @param action Action instance
*/
@SuppressWarnings("rawtypes")
<A extends Action> void clearCache(A action);