如何从会话中清除所有 pageFlowScope 地图?

发布于 2024-12-17 06:30:04 字数 1099 浏览 3 评论 0原文

当我们确定不再需要它时,如何清除 pageFlowScopes 并从会话中查看缓存?

以下清除当前请求上下文中的 pageFlowScope 映射

    RequestContext requestContext = RequestContext.getCurrentInstance();
    requestContext.getPageFlowScope().clear();

,但如果我转储 http-session 属性,我仍然在会话

org.apache.myfaces.trinidadinternal.application.PageFlowScope.ois6p8lk1 
org.apache.myfaces.trinidadinternal.application.PageFlowScope.ois6p8lk2 
org.apache.myfaces.trinidadinternal.application.PageFlowScope.ois6p8lk3 

和视图缓存 中看到许多 PageFlowscopes 实例显然

org.apache.myfaces.trinidadinternal.application.VIEW_CACHE.1qvzgdgkw
org.apache.myfaces.trinidadinternal.application.VIEW_CACHE.2qvzgdgkw
org.apache.myfaces.trinidadinternal.application.VIEW_CACHE.3qvzgdgkw

,如果我清除会话属性,它就会消失,但我不想这样做,还有其他方法吗?

使用

  • trinidad-api-1.0.10.jar
  • myfaces-impl-1.1.5.jar

编辑

还观察到以下属性永远保留在会话中,并且内容随着时间的推移而增长

org.apache.myfaces.trinidadinternal.Change

How to clear pageFlowScopes and view caches from session when we are sure its no longer required?

Following clears pageFlowScope map in current request context

    RequestContext requestContext = RequestContext.getCurrentInstance();
    requestContext.getPageFlowScope().clear();

But if I dump http-session attributes I still see many instances of PageFlowscopes in the session

org.apache.myfaces.trinidadinternal.application.PageFlowScope.ois6p8lk1 
org.apache.myfaces.trinidadinternal.application.PageFlowScope.ois6p8lk2 
org.apache.myfaces.trinidadinternal.application.PageFlowScope.ois6p8lk3 

and view caches as well

org.apache.myfaces.trinidadinternal.application.VIEW_CACHE.1qvzgdgkw
org.apache.myfaces.trinidadinternal.application.VIEW_CACHE.2qvzgdgkw
org.apache.myfaces.trinidadinternal.application.VIEW_CACHE.3qvzgdgkw

Obviously if I clear session attributes it will all go away but I don't want to do that, Is there any other way ?

Using

  • trinidad-api-1.0.10.jar
  • myfaces-impl-1.1.5.jar

EDIT

Also observed following attribute is kept in session forever, and the content grows over time

org.apache.myfaces.trinidadinternal.Change

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓬勃野心 2024-12-24 06:30:04

PageFlowScope

如果不打算使用多个 pageflowscope,可以更改 trinidad-config.xml 中的以下条目,

<page-flow-scope-lifetime>1</page-flow-scope-lifetime>

这将控制 org.apache.myfaces.trinidadinternal.application 的数量.PageFlowScope 保持在会话中。


VIEW_CACHE

如果不打算使用 VIEW_CACHE,可以将 web.xml 中的以下 init params 配置为最小值。

<context-param>
    <param-name>org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS</param-name>
    <param-value>1</param-value>
</context-param>    

<context-param>
    <param-name>
        org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
    </param-name>
    <param-value>1</param-value>
</context-param>

中保存的 org.apache.myfaces.trinidadinternal.application.VIEW_CACHE 数量的控制,


这将保持对会话trinidadinternal.Change

我找不到避免这种情况的方法。


最终使用以下方法进行清理

@SuppressWarnings("unchecked")
public static Map<String, Object> getSessionMap() {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getExternalContext().getSessionMap();
}


private void clearMyfacesSessionAttributes() {
    RequestContext requestContext = RequestContext.getCurrentInstance();
    requestContext.getPageFlowScope().clear();
    Map<String, Object> sessionMap = getSessionMap();
    Set<Map.Entry<String, Object>> entrySet = sessionMap.entrySet();
    for (Map.Entry<String, Object> entry : entrySet) {
        String key = entry.getKey();
        if(key.contains("org.apache.myfaces.trinidadinternal.application.VIEW_CACHE")
                || key.contains("org.apache.myfaces.trinidadinternal.application.PageFlowScope")
                || key.contains("org.apache.myfaces.trinidadinternal.Change"))
        {
            sessionMap.remove(key);
        }
    }
}

PageFlowScope

If not planning to use multiple pageflowscopes following entry in trinidad-config.xml can be altered

<page-flow-scope-lifetime>1</page-flow-scope-lifetime>

This will control number of org.apache.myfaces.trinidadinternal.application.PageFlowScope kept in session.


VIEW_CACHE

If not planning to use VIEW_CACHE following init params in web.xml can be configured to a minimal value.

<context-param>
    <param-name>org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS</param-name>
    <param-value>1</param-value>
</context-param>    

<context-param>
    <param-name>
        org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION
    </param-name>
    <param-value>1</param-value>
</context-param>

This will keep control over number of org.apache.myfaces.trinidadinternal.application.VIEW_CACHE kept in session


trinidadinternal.Change

I couldn't find a way to to avoid this.


Ended up using following method to cleanup

@SuppressWarnings("unchecked")
public static Map<String, Object> getSessionMap() {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getExternalContext().getSessionMap();
}


private void clearMyfacesSessionAttributes() {
    RequestContext requestContext = RequestContext.getCurrentInstance();
    requestContext.getPageFlowScope().clear();
    Map<String, Object> sessionMap = getSessionMap();
    Set<Map.Entry<String, Object>> entrySet = sessionMap.entrySet();
    for (Map.Entry<String, Object> entry : entrySet) {
        String key = entry.getKey();
        if(key.contains("org.apache.myfaces.trinidadinternal.application.VIEW_CACHE")
                || key.contains("org.apache.myfaces.trinidadinternal.application.PageFlowScope")
                || key.contains("org.apache.myfaces.trinidadinternal.Change"))
        {
            sessionMap.remove(key);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文