org.openanzo.server.repository.cache
Class ResourceCache<E extends CachableResource>

java.lang.Object
  extended by org.openanzo.server.repository.cache.ResourceCache<E>
Type Parameters:
E - Cache of Resource objects

public class ResourceCache<E extends CachableResource>
extends java.lang.Object

Provides cached loading and creating and state checking of resources. This is an ever growing cache that is only cleared when clear() is called. For our purposes this is after each request so concurrency issues can be handled exclusively by the database.

Author:
Joe Betz, Matthew Roy ( mroy@cambridgesemantics.com )

Constructor Summary
ResourceCache(java.lang.String cacheName, int cacheSize, CachableResourceFactory<E> cachableFactory, RepositoryConnection repositoryConnection)
          Create a new ResourceCache
 
Method Summary
 void clear()
          Clear the cache of ids and resources
 E create(java.lang.Long id, boolean forceCreate)
          Create a server object with the given ID
 boolean isStored(java.lang.Long id)
          Is the a resource with the given ID stored
 E load(java.lang.Long id)
          Load a resource
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceCache

public ResourceCache(java.lang.String cacheName,
                     int cacheSize,
                     CachableResourceFactory<E> cachableFactory,
                     RepositoryConnection repositoryConnection)
Create a new ResourceCache

Parameters:
cacheName - Name of cache
cacheSize - Size of object cache to create
cachableFactory - Factory to create resources
repositoryConnection - RepositoryConnection to query and update database
Method Detail

load

public E load(java.lang.Long id)
                                throws AnzoException
Load a resource

Parameters:
id - Id of resource
Returns:
Resource the given ID
Throws:
AnzoException

create

public E create(java.lang.Long id,
                boolean forceCreate)
                                  throws AnzoException
Create a server object with the given ID

Parameters:
id - ID of server object
forceCreate - Force creation of resource if not created
Returns:
server object for the given ID
Throws:
AnzoException

isStored

public boolean isStored(java.lang.Long id)
Is the a resource with the given ID stored

Parameters:
id - ID of resource
Returns:
true if a resource with the given ID stored

clear

public void clear()
Clear the cache of ids and resources



Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.