假设我有一个组件A和一个组件B。在组件A中,我正在编写html文件
Lets say I have a component A and component B. In component A, html file I am writing
data-sly-use.head="com.Mymodel"现在在组件B中,我也需要使用相同的类,因此在html文件中,我编写了
now in Component B also I need to use the same class, so in html file I have written
data-sly-use.head="com.Mymodel"组件A和组件B可以在页面中可用,也可以一次不可用。我想要的是,如果页面中同时存在组件A和组件B,那么我就不想两次初始化Sling模型(com.Mymodel)。我只想初始化一次。怎么做?
Component A and Component B can be available in a page or may not be available at a time. What I want is that if both Component A and B present in a page then I do not want to initialise Sling model (com.Mymodel) twice. I would like to initialise only one time. How to do it?
推荐答案看看Sling Model Caching。只要它可以从Resource适应,就可以满足您的要求。
Take a look at Sling Model Caching. This does exactly what you want, as long as it is adaptable from Resource.
sling.apache/documentation/bundles/models.html#caching
您只需在模型注释中指定 cache = true 。
You only have to specify cache=true in the Model-annotation.
@Model(adaptable = SlingHttpServletRequest.class, cache = true) public class ModelClass { ... }更多推荐
如何仅调用吊索模型一次
发布评论