You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Dirk Rudolph (Jira)" <ji...@apache.org> on 2022/02/10 11:08:00 UTC

[jira] [Updated] (SLING-11133) Cache model for its implementation type

     [ https://issues.apache.org/jira/browse/SLING-11133?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dirk Rudolph updated SLING-11133:
---------------------------------
    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. 

While it is not save to cache the model for all of its adapter types (see SLING-11074), it is certainly save to cache the Model for its implementation type additionally to the requested type. In fact, when caching the Model for the implementation type caching it for the requested type is redundant.

  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 an instance of it can also be returned for more than just the requested type. 

While it is not save to cache the model for all of its adapter types (see SLING-11074), it is certainly save to cache the model for its implementation type additionally to the requested type. 


> Cache model for its implementation type
> ---------------------------------------
>
>                 Key: SLING-11133
>                 URL: https://issues.apache.org/jira/browse/SLING-11133
>             Project: Sling
>          Issue Type: Improvement
>          Components: Sling Models
>            Reporter: Dirk Rudolph
>            Priority: Major
>             Fix For: Models Implementation 1.5.2
>
>
> 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. 
> While it is not save to cache the model for all of its adapter types (see SLING-11074), it is certainly save to cache the Model for its implementation type additionally to the requested type. In fact, when caching the Model for the implementation type caching it for the requested type is redundant.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)