2011-06-23 16 views
0
@In 
Identity identity; 

Boolean newValue = identity.hasPermission(target, action); 

對上述方法的任何調用也會執行「從角色r中選擇角色」調用,該調用將從底層接縫引擎調用。如何將此調用的查詢緩存設置爲查詢提示(例如org.hibernate.cacheable標誌),以便它不會再次調用。如何在接縫引擎發出的呼叫上設置查詢緩存

注意:角色信息永遠不會改變,因此我認爲這是一個不必要的sql調用。

回答

0

我不在休眠狀態,但由於這個問題仍未得到解答:我們擴展了接縫的標準Identity類,原因有幾個。您可能還想擴展它以幫助您緩存結果。

由於此緩存是會話作用域,它將有可能的好處是當用戶再次登錄/關閉時它將被重新加載 - 但這取決於您的要求。

此致敬禮, 亞歷山大。

/** 
* Extended Identity to implement i.e. caching 
*/ 
@Name("org.jboss.seam.security.identity") 
@Scope(SESSION) 
@Install(precedence = Install.APPLICATION) 
@BypassInterceptors 
@Startup 
public class MyIdentity extends Identity { 

    // place a concurrent hash map here 

    @Override 
    public boolean hasPermission(Object name, String action) { 
    // either use the use the cached result in the hash map ... 
    // ... or call super.hasPermission() and cache the result 
    } 

}