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

Move Sling Model cache holder for Resource and ResourceResolver adaptables into the resource resolver property map

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Models Implementation 1.6.4
    • None
    • Sling Models
    • None

    Description

      There have been several instances of issues with model caching over the years, the most recent being SLING-12259 and this thread from Jörg Hoh. These recent issues have been around cached items sticking around for too long. In that thread, it was discussed using ResourceResolver#getPropertyMap() whenever possible. This binds the cache to the lifecycle of the ResourceResolver, avoiding the global cache altogether.

      After looking at the current implementation, there is already a divergence that binds the cache for request-based models to the request, by putting the cache in the request attribute.

      This proposes to do a similar change for Resource/Resolver based models, and use the resolver's property map to bind the cache for those adaptables to the lifecycle of the ResourceResolver. Resources are already (largely) bound to the lifecycle of the ResourceResolver that supplied them, and binding the models that come from these Resources seems to be a reasonable approach.

      This will greatly reduce the lifetime of model objects, reducing the likelihood of the JVM's GC being put under pressure in cases when cached models reference the original adaptable using @Self. As a bonus, if the cache object implements Closeable, the Sling Implementation will call close() on the cache when the resolver is closed,, giving us further control over the lifetime of objects in the cache.

      Attachments

        1. cache-size.log
          60 kB
          Sumanta Pakira
        2. cachesize.log
          59 kB
          Sumanta Pakira

        Issue Links

          Activity

            People

              Unassigned Unassigned
              paul.bjorkstrand Paul Bjorkstrand
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: