org.helidb.backend.cache.lru
Class LruCacheBackendFactory<K,V,P>

java.lang.Object
  extended by org.helidb.backend.cache.lru.LruCacheBackendFactory<K,V,P>
Type Parameters:
K - The type of keys in the database.
V - The type of values in the database.
P - The type used to represent positions in the proxied backend.
All Implemented Interfaces:
DatabaseBackendFactory<K,V,P>

public class LruCacheBackendFactory<K,V,P>
extends Object
implements DatabaseBackendFactory<K,V,P>

This is a DatabaseBackendFactory for building LruCacheBackend objects.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
helidb-core

Field Summary
static int DEFAULT_CACHE_SIZE
          The default cache size is 128 records.
static int DEFAULT_NEGATIVE_CACHE_SIZE
          The default negative cache size is 32 keys.
 
Constructor Summary
LruCacheBackendFactory()
           
 
Method Summary
 DatabaseBackend<K,V,P> create(DatabaseFiles files, boolean readOnly)
          Create a new backend for the supplied file.
 LruCacheBackendFactory<K,V,P> setMaxCacheSize(int cacheSize)
          Set the maximum size for the database record cache.
 LruCacheBackendFactory<K,V,P> setMaxNegativeCacheSize(int negativeCacheSize)
          Set the maximum size for the cache for failed search results.
 LruCacheBackendFactory<K,V,P> setProxiedBackendFactory(DatabaseBackendFactory<K,V,P> factory)
          Set the factory for the proxied backend.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CACHE_SIZE

public static final int DEFAULT_CACHE_SIZE
The default cache size is 128 records.

See Also:
Constant Field Values

DEFAULT_NEGATIVE_CACHE_SIZE

public static final int DEFAULT_NEGATIVE_CACHE_SIZE
The default negative cache size is 32 keys.

See Also:
Constant Field Values
Constructor Detail

LruCacheBackendFactory

public LruCacheBackendFactory()
Method Detail

setProxiedBackendFactory

public LruCacheBackendFactory<K,V,P> setProxiedBackendFactory(DatabaseBackendFactory<K,V,P> factory)
Set the factory for the proxied backend. This property must be set.

Parameters:
factory - The factory for the proxied backend.
Returns:
this.

setMaxCacheSize

public LruCacheBackendFactory<K,V,P> setMaxCacheSize(int cacheSize)
                                              throws IllegalArgumentException
Set the maximum size for the database record cache. The default value of this property is 128 records.

Parameters:
cacheSize - The maximum record cache size.
Returns:
this
Throws:
IllegalArgumentException - If the cache size is < 0.

setMaxNegativeCacheSize

public LruCacheBackendFactory<K,V,P> setMaxNegativeCacheSize(int negativeCacheSize)
                                                      throws IllegalArgumentException
Set the maximum size for the cache for failed search results. The default value of this property is 32 keys.

Parameters:
negativeCacheSize - The maximum size for the negative cache.
Returns:
this
Throws:
IllegalArgumentException - If the cache size is < 0.

create

public DatabaseBackend<K,V,P> create(DatabaseFiles files,
                                     boolean readOnly)
Description copied from interface: DatabaseBackendFactory
Create a new backend for the supplied file.

Specified by:
create in interface DatabaseBackendFactory<K,V,P>
Parameters:
files - The file(s) containing the database data. The implementation of this method should be able to assume a specific DatabaseFiles implementation. Which depends on the implementation of the database backend to create.
readOnly - Should the backend object be created read only?
Returns:
A new database backend object.