|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK 11g Release 2 (11.1.2.1.0) E17493-02 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oracle.javatools.util.deferred.DerivedCache<Key,Source,Target>
Key
- The key used to look up a given cached valueSource
- The object that is the source of the derivation, for example location of keystoresTarget
- The object that is the result of the derivation, for example the location of a merged keystorepublic class DerivedCache<Key,Source,Target>
This class looks to deal with the fairly common case where you have an operation that expensively created a value that you need to conserve until such time as it expires.
In order to do this this class takes two parameters that the allow clients to define rules for when resources need to be recreated and who to create those resources when the are needed.
The fetching of the resource and the updating of the source are handled separately in order to simply calling logic. There is a method that will update the source and derrive a new value if required.
{ DerivedCache<String, String, String> smiley = new DerivedCache(new Derive<String, String>() { public String derrive(String a) { return a + " ;-)"; } }); // Asynchronous update smiley.updateSource("Hello", "Hi "); // Asynchronous get String hello = smiley.getValue("Hello"); // Synchronous get and update String synHello = smiley.getValue("Hello", "Salut "); }
This class is thread safe and required no further synchronization.
Nested Class Summary | |
---|---|
static interface |
DerivedCache.Derive<Source,Target>
Derive the source from the target |
static interface |
DerivedCache.Expire<Source,Target>
Given the before and after source do we need to expire the object. |
Constructor Summary | |
---|---|
DerivedCache(DerivedCache.Derive<Source,Target> d)
A helper constructor that create an Expire object that uses object equals to work out if the target need to be expired. |
|
DerivedCache(DerivedCache.Derive<Source,Target> d,
DerivedCache.Expire<Source,Target> e)
A constructor that takes both the Derive and Expire parts. |
Method Summary | |
---|---|
Target |
getValue(Key key)
Get the derived value using the currently existing source |
Target |
getValue(Key key,
Source source)
Get the derived value from a new source |
void |
removeKey(Key key)
Remove the cached values for the given key |
void |
updateSource(Key key,
Source source)
Update the source object for a particular key |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DerivedCache(DerivedCache.Derive<Source,Target> d)
d
- The class used to derive the Targetpublic DerivedCache(DerivedCache.Derive<Source,Target> d, DerivedCache.Expire<Source,Target> e)
d
- The class used to derive the Targete
- The class used to expire the Target based on the SourceMethod Detail |
---|
public void updateSource(Key key, Source source)
key
- The key in the cachesource
- The source of the derivationpublic Target getValue(Key key, Source source) throws java.lang.reflect.InvocationTargetException
key
- The key in the cachesource
- The source of the derivation
java.lang.reflect.InvocationTargetException
- if the target cannot be derived.public Target getValue(Key key) throws java.lang.reflect.InvocationTargetException
key
- The key in the cache
java.lang.reflect.InvocationTargetException
- if the target cannot be derived.public void removeKey(Key key)
key
-
|
Oracle Fusion Middleware Java API Reference for Oracle Extension SDK 11g Release 2 (11.1.2.1.0) E17493-02 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |