Project Wonder 5.0

er.extensions.foundation
Class ERXLazyValue<T>

java.lang.Object
  extended by er.extensions.foundation.ERXLazyValue<T>
Type Parameters:
T - the type of the lazy value

public class ERXLazyValue<T>
extends java.lang.Object

ERXLazyValue provides a way to model lazy-loaded values that invalidate with different methods. This is very useful for storing expensive values that are returned from bound component methods as well as values that are cached that are influenced by different areas of a single page (i.e. ajax operations on one part of the page that need to invalidate a cache on another part of the page).

Author:
mschrag

Nested Class Summary
static class ERXLazyValue.AjaxPageUserInfoCacheKeyInvalidator
          AjaxPageUserInfoCacheKeyInvalidator triggers a cache invalidation when the value of the specified key changes in the ERXResponseRewriter's ajaxPageUserInfo.
static class ERXLazyValue.AlwaysInvalidator
          Returns true from shouldInvalidate, causing the cache to always refresh.
static class ERXLazyValue.CacheKeyInvalidator
          The base class for any invalidator that is triggered by the change in a cache key.
static class ERXLazyValue.ConstantSource<T>
          ConstantSource provides a Source implementation on top of a fixed value.
static interface ERXLazyValue.Invalidator
          Invalidator provides an mechanism for selectively invalidating the cached lazy value.
static class ERXLazyValue.KVCSource<T>
          KVCSource provides a wrapper around a KVC binding, which is very useful in components.
static class ERXLazyValue.MutableCacheKeyInvalidator
          The base class for any invalidator that is triggered by the change in a cache key with support for changing the value.
static class ERXLazyValue.NeverInvalidator
          Returns false from shouldInvalidate, causing the cache to never refresh.
static class ERXLazyValue.PageUserInfoCacheKeyInvalidator
          PageUserInfoCacheKeyInvalidator triggers a cache invalidation when the value of the specified key changes in the ERXResponseRewriter's pageUserInfo.
static interface ERXLazyValue.Source<T>
          A source provides the undelying value (which is usually uncached) to a lazy value.
static class ERXLazyValue.ThreadStorageCacheKeyInvalidator
          ThreadStorageCacheKeyInvalidator triggers a cache invalidation when the value of the specified key changes in the ERXThreadStorage.
static class ERXLazyValue.TimedInvalidator
          TimedInvalidator specifies that the cached value should be invalidated after a specified duration.
 
Field Summary
static org.apache.log4j.Logger log
           
 
Constructor Summary
ERXLazyValue(ERXLazyValue.Source<T> dataSource)
          Constructs a new ERXLazyValue with a data source and a NeverInvalidator, which behaves like a "once" lazy value.
ERXLazyValue(ERXLazyValue.Source<T> dataSource, ERXLazyValue.Invalidator invalidator)
          Constructs a new ERXLazyValue with a data source and an invalidator.
ERXLazyValue(java.lang.Object target, java.lang.String keyPath)
          Constructs a new ERXLazyValue with a shortcut for a KVCSource and a NeverInvalidator, which behaves like a "once" lazy value.
ERXLazyValue(java.lang.Object target, java.lang.String keyPath, ERXLazyValue.Invalidator invalidator)
          Constructs a new ERXLazyValue with a shortcut for a KVCSource and an invalidator.
 
Method Summary
 void invalidate()
          Forecfully invalidates the lazy value, regardless of the state of the invalidator.
 void setValue(T value)
          Sets the backging value for this lazy value, which will always call through to the underlying data source.
 T value()
          Returns the backing value for this lazy value, which will only sometimes trigger a call through to the data source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public static org.apache.log4j.Logger log
Constructor Detail

ERXLazyValue

public ERXLazyValue(ERXLazyValue.Source<T> dataSource)
Constructs a new ERXLazyValue with a data source and a NeverInvalidator, which behaves like a "once" lazy value.

Parameters:
dataSource - the data source for the lazy value

ERXLazyValue

public ERXLazyValue(java.lang.Object target,
                    java.lang.String keyPath)
Constructs a new ERXLazyValue with a shortcut for a KVCSource and a NeverInvalidator, which behaves like a "once" lazy value.

Parameters:
target - the target of the KVCSource
keyPath - the keypath of the KVCSource

ERXLazyValue

public ERXLazyValue(java.lang.Object target,
                    java.lang.String keyPath,
                    ERXLazyValue.Invalidator invalidator)
Constructs a new ERXLazyValue with a shortcut for a KVCSource and an invalidator.

Parameters:
target - the target of the KVCSource
keyPath - the keypath of the KVCSource
invalidator - the invalidator to use

ERXLazyValue

public ERXLazyValue(ERXLazyValue.Source<T> dataSource,
                    ERXLazyValue.Invalidator invalidator)
Constructs a new ERXLazyValue with a data source and an invalidator.

Parameters:
dataSource - the data source for the lazy value
invalidator - the invalidator to use
Method Detail

invalidate

public void invalidate()
Forecfully invalidates the lazy value, regardless of the state of the invalidator.


value

public T value()
Returns the backing value for this lazy value, which will only sometimes trigger a call through to the data source.

Returns:
the backing value

setValue

public void setValue(T value)
Sets the backging value for this lazy value, which will always call through to the underlying data source. This will also cache the new value and notify the invalidator of a new fetched value (acting just like if value() was called on an invalidated cache).

Parameters:
value - the new value

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.