You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by GitBox <gi...@apache.org> on 2022/02/13 09:11:32 UTC

[GitHub] [struts] lukaszlenart edited a comment on pull request #528: Potential expression cache enhancement for 2.6 series

lukaszlenart edited a comment on pull request #528:
URL: https://github.com/apache/struts/pull/528#issuecomment-1037946560


   You can inject them via constructor if you want to or provide a factory which will be injected into `OgnlUtil` and this factory will be used to create a proper instance of cache:
   
   ```java
   public OgnlUtil(
       @Inject(StrutsConstants.STRUTS_EXPRESSION_CACHE_FACTORY, required = false) ExpressionCacheFactory cacheFactory
   ) {
       if (cacheFactory == null) {
           // fallback to old mechanism
       } else {
          this.cache = cacheFactory.createCacheInstance();
       }
   }
   ```
   
   and the factory:
   
   ```java
   class ExpressionCacheFactory {
   
       @Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_CACHE_MAXSIZE, required = false)
       protected void setExpressionsCacheMaxSize(String maxSize) {
           expressionsCacheMaxSize.set(Integer.parseInt(maxSize));
           expressionsCacheLRU.setEvictionLimit(expressionsCacheMaxSize.get());
       }
   
       @Inject(value = StrutsConstants.STRUTS_OGNL_BEANINFO_CACHE_MAXSIZE, required = false)
       protected void setBeanInfoCacheMaxSize(String maxSize) {
           beanInfoCacheMaxSize.set(Integer.parseInt(maxSize));
           beanInfoCacheLRU.setEvictionLimit(beanInfoCacheMaxSize.get());
       }
   
       @Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_CACHE_LRU_MODE, required = false)
       protected void setUseLRUExpressionCache(String useLRUMode) {
           useLRUExpressionCache.set(BooleanUtils.toBoolean(useLRUMode));
       }
   
       @Inject(value = StrutsConstants.STRUTS_OGNL_BEANINFO_CACHE_LRU_MODE, required = false)
       protected void setUseLRUBeanInfoCache(String useLRUMode) {
           useLRUBeanInfoCache.set(BooleanUtils.toBoolean(useLRUMode));
       }
   
       public CacheInstance createCacheInstance() {
             ....
        }
   
   }
   ```
   
   Then you just need to define a bean in `struts-default.xml` and done :)
   
   Take your time and if you need my help let me know. Or if you want to, I can refactor your code once we merge this PR - working with DI in Struts can be frustrating on the beginning ;-)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org