Index: branches/OaaS/HeuristicLab.Parameters/3.3/LookupParameter.cs
===================================================================
--- branches/OaaS/HeuristicLab.Parameters/3.3/LookupParameter.cs	(revision 8228)
+++ branches/OaaS/HeuristicLab.Parameters/3.3/LookupParameter.cs	(revision 9363)
@@ -21,4 +21,5 @@
 
 using System;
+using System.Threading;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -31,5 +32,5 @@
   [Item("LookupParameter", "A parameter whose value is retrieved from or written to a scope.")]
   [StorableClass]
-  public class LookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem {
+  public class LookupParameter<T> : Parameter, IStatefulItem, ILookupParameter<T> where T : class, IItem {
     [Storable]
     private string actualName;
@@ -59,9 +60,31 @@
     }
 
+    private Lazy<ThreadLocal<IItem>> cachedActualValues;
+    private IItem CachedActualValue {
+      get { return cachedActualValues.Value.Value; }
+    }
+
+    private Lazy<ThreadLocal<IExecutionContext>> executionContexts;
+    public IExecutionContext ExecutionContext {
+      get { return executionContexts.Value.Value; }
+      set {
+        if (value != executionContexts.Value.Value) {
+          executionContexts.Value.Value = value;
+          cachedActualValues.Value.Value = null;
+        }
+      }
+    }
+
     [StorableConstructor]
-    protected LookupParameter(bool deserializing) : base(deserializing) { }
+    protected LookupParameter(bool deserializing)
+      : base(deserializing) {
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+    }
     protected LookupParameter(LookupParameter<T> original, Cloner cloner)
       : base(original, cloner) {
       actualName = original.actualName;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter()
@@ -69,4 +92,6 @@
       this.actualName = Name;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter(string name)
@@ -74,4 +99,6 @@
       this.actualName = Name;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter(string name, string description)
@@ -79,4 +106,6 @@
       this.actualName = Name;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
     public LookupParameter(string name, string description, string actualName)
@@ -84,4 +113,6 @@
       this.actualName = string.IsNullOrWhiteSpace(actualName) ? Name : actualName;
       this.Hidden = true;
+      cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
     }
 
@@ -132,4 +163,5 @@
     }
     protected override IItem GetActualValue() {
+      if (CachedActualValue != null) return CachedActualValue;
       string name;
       // try to get value from context stack
@@ -146,4 +178,5 @@
                           typeof(T).GetPrettyName())
           );
+        cachedActualValues.Value.Value = var.Value;
         return var.Value;
       }
@@ -156,4 +189,6 @@
                         typeof(T).GetPrettyName())
         );
+      cachedActualValues.Value.Value = value;
+
       // try to set value in context stack
       string name;
@@ -175,4 +210,17 @@
     }
 
+    public virtual void InitializeState() {
+    }
+    public virtual void ClearState() {
+      if (cachedActualValues.IsValueCreated) {
+        cachedActualValues.Value.Dispose();
+        cachedActualValues = new Lazy<ThreadLocal<IItem>>(() => { return new ThreadLocal<IItem>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      }
+      if (executionContexts.IsValueCreated) {
+        executionContexts.Value.Dispose();
+        executionContexts = new Lazy<ThreadLocal<IExecutionContext>>(() => { return new ThreadLocal<IExecutionContext>(); }, LazyThreadSafetyMode.ExecutionAndPublication);
+      }
+    }
+
     public event EventHandler ActualNameChanged;
     protected virtual void OnActualNameChanged() {
