Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11074

Cache model for all of its adapter types

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • Sling Models
    • None

    Description

      Currently the ModelAdapterFactory caches a cacheable model for the requested type only

      https://github.com/apache/sling-org-apache-sling-models-impl/blob/master/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L430-L432

      if (result.wasSuccessful() && modelAnnotation.cache() && adaptableCache != null) {
        adaptableCache.put(requestedType, new SoftReference<Object>(result.getValue()));
      }
      

      However, if a model is an adapter of multiple types an instance of it can also be returned for more than just the requested type.

      Caching the model for each of its adapter types may improve the cache hit ratio.

      interface A {}
      interface B {}
      
      @Model(cache=true, adaptables=Resource.class, adapters={A.class, B.class})
      class Model implements A, B {}
      
      assertSame(givenResource.adaptTo(A.class), givenResource.adaptTo(B.class))
      

      Attachments

        Activity

          People

            diru Dirk Rudolph
            diru Dirk Rudolph
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m