goldengate.common.lru
Interface InterfaceLruCache<K,V>

All Known Implementing Classes:
AbstractLruCache, SoftReferenceSynchronizedLruCache, SynchronizedLruCache

public interface InterfaceLruCache<K,V>

LRU cache interface.

Author:
Frederic Bregier, Damian Momot

Method Summary
 void clear()
          Removes all entries from cache
 boolean contains(K key)
          Checks whether cache contains valid entry for key
 void forceClearOldest()
          Removes all oldest entries from cache (ttl based)
 V get(K key)
          Returns value cached with key.
 V get(K key, Callable<V> callback)
          Tries to get element from cache.
 V get(K key, Callable<V> callback, long ttl)
          Tries to get element from cache.
 int getCapacity()
          Returns cache capacity
 int getSize()
          Returns number of entries stored in cache (including invalid ones)
 long getTtl()
          Returns cache TTL
 boolean isEmpty()
          Checks whether cache is empty.
 void put(K key, V value)
          Puts value under key into cache.
 void put(K key, V value, long ttl)
          Puts value under key into cache with desired TTL
 void remove(K key)
          Removes entry from cache (if exists)
 

Method Detail

clear

void clear()
Removes all entries from cache


forceClearOldest

void forceClearOldest()
Removes all oldest entries from cache (ttl based)


contains

boolean contains(K key)
Checks whether cache contains valid entry for key

Parameters:
key -
Returns:
true if cache contains key and entry is valid

get

V get(K key)
Returns value cached with key.

Parameters:
key -
Returns:
value or null if key doesn't exist or entry is not valid

get

V get(K key,
      Callable<V> callback)
      throws Exception
Tries to get element from cache. If get fails callback is used to create element and returned value is stored in cache. Default TTL is used

Parameters:
key -
callback -
Returns:
Value
Throws:
Exception - if callback throws exception

get

V get(K key,
      Callable<V> callback,
      long ttl)
      throws Exception
Tries to get element from cache. If get fails callback is used to create element and returned value is stored in cache

Parameters:
key -
callback -
ttl - time to live in milliseconds
Returns:
Value
Throws:
Exception - if callback throws exception

getCapacity

int getCapacity()
Returns cache capacity

Returns:
capacity of cache

getSize

int getSize()
Returns number of entries stored in cache (including invalid ones)

Returns:
number of entries

getTtl

long getTtl()
Returns cache TTL

Returns:
ttl in milliseconds

isEmpty

boolean isEmpty()
Checks whether cache is empty. If any entry exists (including invalid one) this method will return true

Returns:
true if no entries are stored in cache

put

void put(K key,
         V value)
Puts value under key into cache. Default TTL is used

Parameters:
key -
value -

put

void put(K key,
         V value,
         long ttl)
Puts value under key into cache with desired TTL

Parameters:
key -
value -
ttl - time to live in milliseconds

remove

void remove(K key)
Removes entry from cache (if exists)

Parameters:
key -


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.