001package icy.image.cache;
002
003import java.util.Collection;
004
005public abstract class AbstractCache
006{
007    boolean profiling;
008    long profilingTime;
009    long startTime;
010
011    public AbstractCache()
012    {
013        super();
014
015        profiling = false;
016    }
017
018    public abstract String getName();
019
020    public void setProfiling(boolean value)
021    {
022        profiling = value;
023    }
024
025    public void resetProfiling()
026    {
027        profilingTime = 0L;
028    }
029
030    public long getProfilingTime()
031    {
032        return profilingTime;
033    }
034
035    protected void startProf()
036    {
037        startTime = System.nanoTime();
038    }
039
040    protected void endProf()
041    {
042        profilingTime += (System.nanoTime() - startTime) / 1000000L;
043    }
044
045    /**
046     * Returns true if the cache is enabled
047     */
048    public abstract boolean isEnabled();
049
050    /**
051     * Test presence of a key in the cache
052     */
053    public abstract boolean isInCache(Integer key);
054
055    /**
056     * Test presence of a key in the cache
057     */
058    public abstract boolean isOnMemoryCache(Integer key);
059
060    /**
061     * Test presence of a key in the cache
062     */
063    public abstract boolean isOnDiskCache(Integer key);
064
065    /**
066     * Return used memory for cache (in bytes)
067     */
068    public abstract long usedMemory();
069
070    /**
071     * Return used disk space for cache (in bytes)
072     */
073    public abstract long usedDisk();
074
075    /**
076     * Get all element keys in the cache
077     */
078    public abstract Collection<Integer> getAllKeys() throws CacheException;
079
080    /**
081     * Get an object from cache from its key
082     */
083    public abstract Object get(Integer key) throws CacheException;
084
085    /**
086     * Put an object in cache with its associated key
087     */
088    public abstract void set(Integer key, Object object, boolean eternal) throws CacheException;
089
090    /**
091     * Clear the cache
092     */
093    public abstract void clear() throws CacheException;
094
095    /**
096     * Remove an object from the cache from its key
097     */
098    public abstract void remove(Integer key) throws CacheException;
099
100    /**
101     * Call it when you're done with the cache (release resources and cleanup)
102     */
103    public abstract void end();
104}