001    /*****************************************************************************
002     * Copyright (c) PicoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
009     *****************************************************************************/
010    
011    package org.picocontainer.behaviors;
012    
013    import java.io.Serializable;
014    
015    import org.picocontainer.ComponentAdapter;
016    import org.picocontainer.ObjectReference;
017    
018    /**
019     * <p>
020     * This behavior supports caches values per thread.
021     * </p>
022     *
023     * @author Paul Hammant
024     */
025    public final class ThreadCached<T> extends Stored<T>{
026    
027        public ThreadCached(ComponentAdapter<T> delegate) {
028            super(delegate, new ThreadLocalReference<T>());
029        }
030    
031        public static class ThreadLocalReference<T> extends ThreadLocal<T> implements ObjectReference<T>, Serializable {
032        }
033    
034        public String toString() {
035            return "ThreadCached:" + super.toString();
036        }
037    }