org.specrunner.util.cache.core
Class CacheLRU<K,T>

java.lang.Object
  extended by org.specrunner.util.cache.core.CacheLRU<K,T>
Type Parameters:
K - Key type.
T - The cache object type.
All Implemented Interfaces:
ICache<K,T>

public class CacheLRU<K,T>
extends Object
implements ICache<K,T>

LRU implementation of a cache.

Author:
Thiago Santos

Field Summary
 
Fields inherited from interface org.specrunner.util.cache.ICache
DEFAULT_FEATURE_CLEAN, DEFAULT_FEATURE_SIZE, DEFAULT_FEATURE_TIMEOUT, FEATURE_CLEAN, FEATURE_SIZE, FEATURE_TIMEOUT
 
Constructor Summary
CacheLRU(String name, ICacheCleaner<T> cleaner)
          Basic constructor.
 
Method Summary
 boolean contains(K key)
          Says if a key is mapped.
 T get(K key)
          Get a cache object.
 ICacheCleaner<T> getCleaner()
          Get the cache cleaner.
 String getName()
          Get the cache name.
 ICache<K,T> put(K key, T value)
          Put an element to the cache.
 void release()
          Release cache.
 void remove(K key)
          Remove an object from cache.
 ICache<K,T> setClean(long clean)
          Set cache number of removed elements on cache overload.
 ICache<K,T> setCleaner(ICacheCleaner<T> cleaner)
          Set the cleaner.
 ICache<K,T> setName(String name)
          Set a cache name.
 ICache<K,T> setSize(long size)
          Set cache max size.
 ICache<K,T> setTimeout(long timeout)
          Set cache elements timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheLRU

public CacheLRU(String name,
                ICacheCleaner<T> cleaner)
Basic constructor.

Parameters:
name - The cache name.
cleaner - A cleaner.
Method Detail

getName

public String getName()
Description copied from interface: ICache
Get the cache name.

Specified by:
getName in interface ICache<K,T>
Returns:
The name.

setName

public ICache<K,T> setName(String name)
Description copied from interface: ICache
Set a cache name.

Specified by:
setName in interface ICache<K,T>
Parameters:
name - A cache.
Returns:
The cache itself.

getCleaner

public ICacheCleaner<T> getCleaner()
Description copied from interface: ICache
Get the cache cleaner.

Specified by:
getCleaner in interface ICache<K,T>
Returns:
The cleaner.

setCleaner

public ICache<K,T> setCleaner(ICacheCleaner<T> cleaner)
Description copied from interface: ICache
Set the cleaner.

Specified by:
setCleaner in interface ICache<K,T>
Parameters:
cleaner - A cleaner.
Returns:
The cache itself.

setTimeout

public ICache<K,T> setTimeout(long timeout)
Description copied from interface: ICache
Set cache elements timeout.

Specified by:
setTimeout in interface ICache<K,T>
Parameters:
timeout - The timeout.
Returns:
The cache itself.

setSize

public ICache<K,T> setSize(long size)
Description copied from interface: ICache
Set cache max size.

Specified by:
setSize in interface ICache<K,T>
Parameters:
size - The size.
Returns:
The cache itself.

setClean

public ICache<K,T> setClean(long clean)
Description copied from interface: ICache
Set cache number of removed elements on cache overload.

Specified by:
setClean in interface ICache<K,T>
Parameters:
clean - The number of items to be removed.
Returns:
The cache itself.

contains

public boolean contains(K key)
Description copied from interface: ICache
Says if a key is mapped.

Specified by:
contains in interface ICache<K,T>
Parameters:
key - The key.
Returns:
true, if mapped, false, otherwise.

get

public T get(K key)
Description copied from interface: ICache
Get a cache object.

Specified by:
get in interface ICache<K,T>
Parameters:
key - The object key.
Returns:
A object, if an entry exists and is not out of date, null, otherwise.

put

public ICache<K,T> put(K key,
                       T value)
Description copied from interface: ICache
Put an element to the cache.

Specified by:
put in interface ICache<K,T>
Parameters:
key - The key.
value - The object value.
Returns:
The cache itself.

remove

public void remove(K key)
Description copied from interface: ICache
Remove an object from cache.

Specified by:
remove in interface ICache<K,T>
Parameters:
key - The key.

release

public void release()
Description copied from interface: ICache
Release cache.

Specified by:
release in interface ICache<K,T>


Copyright © 2014. All rights reserved.