Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


oracle.javatools.util.deferred
Class DerivedCache<Key,Source,Target>

java.lang.Object
  extended by oracle.javatools.util.deferred.DerivedCache<Key,Source,Target>

Type Parameters:
Key - The key used to look up a given cached value
Source - The object that is the source of the derivation, for example location of keystores
Target - The object that is the result of the derivation, for example the location of a merged keystore

public class DerivedCache<Key,Source,Target>
extends java.lang.Object

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

DerivedCache

public 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.
Parameters:
d - The class used to derive the Target

DerivedCache

public DerivedCache(DerivedCache.Derive<Source,Target> d,
                    DerivedCache.Expire<Source,Target> e)
A constructor that takes both the Derive and Expire parts. Both of these classes may be singleton if they carry no state.
Parameters:
d - The class used to derive the Target
e - The class used to expire the Target based on the Source

Method Detail

updateSource

public void updateSource(Key key,
                         Source source)
Update the source object for a particular key
Parameters:
key - The key in the cache
source - The source of the derivation

getValue

public Target getValue(Key key,
                       Source source)
                throws java.lang.reflect.InvocationTargetException
Get the derived value from a new source
Parameters:
key - The key in the cache
source - The source of the derivation
Returns:
The derived value
Throws:
java.lang.reflect.InvocationTargetException - if the target cannot be derived.

getValue

public Target getValue(Key key)
                throws java.lang.reflect.InvocationTargetException
Get the derived value using the currently existing source
Parameters:
key - The key in the cache
Returns:
The derived value
Throws:
java.lang.reflect.InvocationTargetException - if the target cannot be derived.

removeKey

public void removeKey(Key key)
Remove the cached values for the given key
Parameters:
key -

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


Copyright © 1997, 2012, Oracle. All rights reserved.