Interface Cache.Handler<V>

Type Parameters:
V - the type of value objects.
All Known Implementing Classes:
Cache.Simple, Cache.Work, Cache.Work.Wait
Enclosing class:
Cache<K,V>

public static interface Cache.Handler<V>
The handler returned by Cache.lock(K), to be used for unlocking and storing the result. This handler should be used as below (the tryfinally statements are important): See the Cache javadoc for a more complete example.
Since:
0.3
Version:
0.3
  • Method Summary

    Modifier and Type
    Method
    Description
    If the value is already in the cache, returns it.
    void
    putAndUnlock(V result)
    Stores the given value in the cache and release the lock.
  • Method Details

    • peek

      V peek()
      If the value is already in the cache, returns it. Otherwise returns null. This method should be invoked after the Handler creation in case a value has been computed in another thread.
      Returns:
      the value from the cache, or null if none.
    • putAndUnlock

      void putAndUnlock(V result) throws IllegalStateException
      Stores the given value in the cache and release the lock. This method must be invoked in a finally block, no matter what the result is.
      Parameters:
      result - the result to store in the cache, or null for removing the entry from the cache. If an entry is removed, a new computation will be attempted the next time a handler is created for the same key.
      Throws:
      IllegalStateException - may be thrown if this method is not invoked in the pattern described in class javadoc, or if a key collision occurs.