001    // Copyright 2008, 2009 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.annotations;
016    
017    import java.lang.annotation.*;
018    
019    import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
020    import org.apache.tapestry5.ioc.annotations.UseWith;
021    
022    /**
023     * Indicates that a method should only be evaluated once and the result cached. All further calls to the method will
024     * return the cached result. Note that this annotation is inheritence-safe; if a subclass calls a superclass method that
025     * has \@Cached then the value the subclass method gets is the cached value.
026     * <p/>
027     * The watch parameter can be passed a binding expression which will be evaluated each time the method is called. The
028     * method will then only be executed the first time it is called and after that only when the value of the binding
029     * changes. This can be used, for instance, to have the method only evaluated once per iteration of a loop by setting
030     * watch to the value or index of the loop.
031     */
032    @Target(ElementType.METHOD)
033    @Retention(RetentionPolicy.RUNTIME)
034    @Documented
035    @UseWith({COMPONENT,MIXIN,PAGE})
036    public @interface Cached
037    {
038        /**
039         * The optional binding to watch (default binding prefix is "prop").
040         */
041        String watch() default "";
042    }