Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-2244

Add @Cached annotation for caching method values

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.10
    • Fix Version/s: 5.0.11
    • Component/s: tapestry-core
    • Labels:
      None

      Description

      The @Once annotation can be used on methods to cache the value or cache the value based on some other value changing (great for loops). We've been using it in our internal CMS library and it's immensly useful, especially when getting things out of any kind of database or doing queries. Here's a typical usage:

      class:
      @Once
      public List<Entities> getEntities() {
      // get and return the objects from the database or something
      }

      in the template:
      <t:if test="!entities.empty">
      do something
      </t:if>

      <t:loop source="entities">
      loop through and do something
      </t:loop>

      In this example, getEntities gets cached on the if test and then the value is cached so it doesn't get called again on the loop. You can also use it this way:

      @Property
      private Entity loopValue;

      @Once(watch="loopValue")
      public Object getSomeDependentValue() {
      // do some expensive operation based on loopValue
      }

      which will only execute the method each time loopValue changes.

        Attachments

          Activity

            People

            • Assignee:
              hagios17 Dan Adams
              Reporter:
              hagios17 Dan Adams
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: