[
https://issues.apache.org/jira/browse/SLING-11074?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dirk Rudolph updated SLING-11074:
---------------------------------
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
{code}
if (result.wasSuccessful() && modelAnnotation.cache() && adaptableCache !=
null) {
adaptableCache.put(requestedType, new
SoftReference<Object>(result.getValue()));
}
{code}
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.
{code}
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))
{code}
was:
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
{code}
if (result.wasSuccessful() && modelAnnotation.cache() && adaptableCache !=
null) {
adaptableCache.put(requestedType, new
SoftReference<Object>(result.getValue()));
}
{code}
However, if a model is an adapter of multiple types it can also be returned for
more than just the requested type. Caching the model for each of the adapter
types may improve the cache hit ratio.
{code}
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))
{code}
> Cache model for all of its adapter types
> ----------------------------------------
>
> Key: SLING-11074
> URL: https://issues.apache.org/jira/browse/SLING-11074
> Project: Sling
> Issue Type: Improvement
> Components: Sling Models
> Reporter: Dirk Rudolph
> Priority: Major
>
> 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
> {code}
> if (result.wasSuccessful() && modelAnnotation.cache() && adaptableCache !=
> null) {
> adaptableCache.put(requestedType, new
> SoftReference<Object>(result.getValue()));
> }
> {code}
> 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.
> {code}
> 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))
> {code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)