net.java.ao.cache
Interface Cache

All Known Implementing Classes:
RAMCache

public interface Cache

The super-interface for all value cache implementations. Implementations of this interface create an instance of CacheLayer for a given RawEntity. The design is such that any implementation of this interface acts as the primary controller for the cache, delegating entity-specific tasks to a custom implementation of CacheLayer. Any resources which are associated with a cache should be managed within the implementation of this interface.

An example design would be for caching in a database (a patently useless operation, given the function of the framework). In this cache, the database itself would be managed in the implementation of ValueCache. This class would then instantiate instances of a custom CacheLayer implementation which would handle the actual act of caching data for specific RawEntity instances (most likely each corresponding with a single row). By separating these implementations, it is possible keep resources handled in a central controller while still devoting distinct memory space to specific entities. The distinct memory is most important in the default implementation, RAMCache.

Generically, implementations of ValueCache function as a factory and controller for the relevant implementation of CacheLayer. The primary purpose is to construct new instances of the implementation-specific CacheLayer and to manage resources common to all constructed instances.

Author:
Daniel Spiewak
See Also:
createCacheLayer(RawEntity), EntityManager.setCache(Cache), EntityManager.getCache()

Method Summary
 CacheLayer createCacheLayer(RawEntity<?> entity)
          Retrieves a CacheLayer instance which corresponds to the given entity.
 void dispose()
          Frees all resources associated with the cache.
 RelationsCache getRelationsCache()
           
 

Method Detail

createCacheLayer

CacheLayer createCacheLayer(RawEntity<?> entity)

Retrieves a CacheLayer instance which corresponds to the given entity. CacheLayer instance(s) may themselves be cached within the value cache, but this is not part of the specification. Generically, this method should return an instance of a working CacheLayer implementation which can persist values relevant to the given entity in an implementation-specific way. For example, the default implementation of this interface (RAMCache) returns a CacheLayer which can cache values in memory for a specific entity.

Typically, instances of the same implementation are returned for any given entity (e.g. RAMCacheLayer always returns an instance of RAMValueCache, regardless of the entity in question). It is theoretically possible however to differentiate layers based on entity type or even specific primary key value. I'm not sure why you would want to do this, but there's nothing in the requirements which would prevent it. Code which uses the result of this method should certainly be written to the interface, rather than any specific implementation.

Parameters:
entity - TODO
Returns:
A layer which will handle caching of values as necessary for the given entity.

getRelationsCache

RelationsCache getRelationsCache()

dispose

void dispose()
Frees all resources associated with the cache. This should be used to handle things like closing connections, freeing result-sets, etc. This method will be called by EntityManager on the old ValueCache when a new instance is specified.

See Also:
EntityManager.setCache(Cache)


Copyright © 2007-2011. All Rights Reserved.