org.hackystat.dailyprojectdata.frontsidecache
Class FrontSideCache

java.lang.Object
  extended by org.hackystat.dailyprojectdata.frontsidecache.FrontSideCache

public class FrontSideCache
extends java.lang.Object

A cache for successfully DPD instances. It is a "front side" cache, in the sense that it faces the clients, as opposed to the caches associated with the SensorDataClient instances, which are "back side" in that they cache sensor data instances. While the "back side" caches avoid calls to the lower-level sensorbase, this front-side cache avoids the overhead of DPD computation itself.

The front side cache is organized as follows. Each DPD instance is associated with a project and a project owner. The FrontSideCache is implemented as a collection of UriCaches, one for each project owner. When a client adds data to the FrontSideCache, it must supply the project owner (which is used to figure out which UriCache to use), the URI of the DPD request (which is the key), and the string representation of the DPD (which is the value).

The FrontSideCache currently has hard-coded maxLife of 1000 hours and each UriCache has a capacity of 1M instances. We could set these via ServerProperties values if necessary.

There is one important component missing from the FrontSideCache, and that is access control. The FrontSideCache does not check to see if the client checking the cache has the right to retrieve the cached data. To perform access control, you should use the SensorDataClient.inProject(owner, project) method, which checks to see if the user associated with the SensorDataClient instance has the right to access information about the project identified by the passed owner/project pair. To see how this works, here is some example get code, which checks the cache but only returns the DPD instance if the calling user is in the project:

 String cachedDpd = this.server.getFrontSideCache().get(uriUser, uriString);
 if (cachedDpd != null && client.inProject(authUser, project)) {
   return super.getStringRepresentation(cachedDpd);
 }
 

Author:
Philip Johnson

Constructor Summary
FrontSideCache(Server server)
          Creates a new front-side cache, which stores the DPD instances recently created.
 
Method Summary
 void clear(java.lang.String user)
          Clears the cache associated with user.
 void clear(java.lang.String user, java.lang.String project)
          Clears all of the cached DPD instances associated with this project and user.
 java.lang.String get(java.lang.String user, java.lang.String project, java.lang.String uri)
          Returns the string representation of the DPD associated with the DPD owner and the URI, or null if not in the cache.
 void put(java.lang.String user, java.lang.String project, java.lang.String uri, java.lang.String dpdRepresentation)
          Adds a (user, dpd) pair to this front-side cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FrontSideCache

public FrontSideCache(Server server)
Creates a new front-side cache, which stores the DPD instances recently created. There should be only one of these created for a given DPD server. Note that this assumes that only one DPD service is running on a given file system.

Parameters:
server - The DPD server associated with this cache.
Method Detail

put

public void put(java.lang.String user,
                java.lang.String project,
                java.lang.String uri,
                java.lang.String dpdRepresentation)
Adds a (user, dpd) pair to this front-side cache. The associated UriCache for this user is created if it does not already exist. Does nothing if frontsidecaching is disabled.

Parameters:
user - The user who is the owner of the project associated with this DPD.
project - The name of the project.
uri - The URL naming this DPD, as a string.
dpdRepresentation - A string representing the DPD instance.

get

public java.lang.String get(java.lang.String user,
                            java.lang.String project,
                            java.lang.String uri)
Returns the string representation of the DPD associated with the DPD owner and the URI, or null if not in the cache.

Parameters:
user - The user who is the owner of the Project associated with this DPD.
uri - The URI naming this DPD.
project - The project associated with this URI.
Returns:
The string representation of the DPD, or null.

clear

public void clear(java.lang.String user)
Clears the cache associated with user. Instantiates one if not available so that any persistent cache that has not yet been read into memory is cleared.

Parameters:
user - The user whose cache is to be cleared.

clear

public void clear(java.lang.String user,
                  java.lang.String project)
Clears all of the cached DPD instances associated with this project and user.

Parameters:
user - The user.
project - The project.