如何仅调用吊索模型一次

编程入门 行业动态 更新时间:2024-10-25 06:27:44
本文介绍了如何仅调用吊索模型一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我有一个组件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 { ... }

更多推荐

如何仅调用吊索模型一次

本文发布于:2023-10-23 22:36:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:吊索   模型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!