سؤال

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
هل كانت مفيدة؟

المحلول

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);
        }
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top