|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hackystat.dailyprojectdata.frontsidecache.FrontSideCache
public class FrontSideCache
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); }
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 |
---|
public FrontSideCache(Server server)
server
- The DPD server associated with this cache.Method Detail |
---|
public void put(java.lang.String user, java.lang.String project, java.lang.String uri, java.lang.String dpdRepresentation)
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.public java.lang.String get(java.lang.String user, java.lang.String project, java.lang.String uri)
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.
public void clear(java.lang.String user)
user
- The user whose cache is to be cleared.public void clear(java.lang.String user, java.lang.String project)
user
- The user.project
- The project.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |