[ https://issues.apache.org/jira/browse/SLING-12279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17846765#comment-17846765 ]
Sumanta Pakira edited comment on SLING-12279 at 5/15/24 10:29 PM: ------------------------------------------------------------------ I think still the problem mentioned in SLING-12259 does not resolve. I tested your code locally and attached is the cache entries which grows as the number of cache request grows. The Softreference does not gets removed by the GC because here the value of the cacheMap or the adapterCache simply grows over time. [^cachesize.log] Probably LRU cache could be useful. was (Author: JIRAUSER304453): I think still the problem mentioned in SLING-12259 does not resolve. I tested your code locally and attached is the cache entries which grows as the number of request grows. The Softreference does not gets removed by the GC because here the value of the cacheMap or the adapterCache simply grows over time. [^cachesize.log] Probably LRU cache could be useful. > Move Sling Model cache holder for Resource and ResourceResolver adaptables > into the resource resolver property map > ------------------------------------------------------------------------------------------------------------------ > > Key: SLING-12279 > URL: https://issues.apache.org/jira/browse/SLING-12279 > Project: Sling > Issue Type: Improvement > Components: Sling Models > Affects Versions: Models Implementation 1.6.4 > Reporter: Paul Bjorkstrand > Priority: Major > Attachments: cache-size.log, cachesize.log > > > There have been several instances of issues with model caching over the > years, the most recent being SLING-12259 and [this > thread|https://www.mail-archive.com/dev@sling.apache.org/msg131926.html] 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()|https://github.com/apache/sling-org-apache-sling-api/blob/master/src/main/java/org/apache/sling/api/resource/ResourceResolver.java#L888]}} > whenever possible. This binds the cache to the lifecycle of the > ResourceResolver, avoiding the global cache altogether. > After looking at the [current > implementation|https://github.com/apache/sling-org-apache-sling-models-impl/blob/master/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L341], > 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}}|https://sling.apache.org/documentation/bundles/models.html#a-note-about-cache-true-and-using-the-self-injector]. > 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. -- This message was sent by Atlassian Jira (v8.20.10#820010)