Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds initial documentation on OGNL cache configuration #183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions source/core-developers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and [results](result-configuration). Each may be configured via XML or annotatio
- [struts-default.xml](struts-default-xml)
- [velocity.properties](velocity-properties)
- [struts-default.vm](struts-default-vm)
- [OGNL Cache Configuration](ognl-cache-configuration)
- [Application Servers](application-servers)
- [Performance Tuning](performance-tuning)
- [Security](../security/)
Expand Down
90 changes: 90 additions & 0 deletions source/core-developers/ognl-cache-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
layout: core-developers
title: OGNL Cache Configuration
---

# OGNL Cache Configuration

The Struts framework provides two different OGNL caches, an expression cache and a BeanInfo cache.
Developers may set properties in [struts.xml](struts-xml) and/or [default.properties](default-properties) to
configure certain behaviours for the OGNL caches. The properties that can be set vary between Struts
versions, referring to the configuration files in a given version should provide guidance in that respect.

The OGNL expression cache is enabled by default. Developers can toggle that state via default.properties:
```
struts.ognl.enableExpressionCache=true
```
or
```
struts.ognl.enableExpressionCache=false
```
The same toggle is also available via struts.xml:
```
<constant name="struts.ognl.enableExpressionCache" value="true"/>
```
or
```
<constant name="struts.ognl.enableExpressionCache" value="false"/>
```

Disabling the OGNL expression cache can have a negative impact on performance, but
disabling the cache can limit memory overhead for the application (a trade-off).

As of Struts 6.0.0, additional configuration properties have been made available to control the
OGNL cache configuration. These include a configureable cache size limit, and activating
an LRU (Least Recently Used) cache mode. The expression cache and BeanInfo cache can have
their properties set independently. Both caches are standard caches with a high maximum
capacity by default. The developer may override the default behaviour using the
appropriate configuration properties.

Below are some examples of setting the cache configuration via default.properties:
```
### Set expression and BeanInfo caches to size 1250 with standard cache mode
struts.ognl.enableExpressionCache=true
struts.ognl.expressionCacheMaxSize=1250
struts.ognl.expressionCacheLRUMode=false
struts.ognl.beanInfoCacheMaxSize=1250
struts.ognl.beanInfoCacheLRUMode=false
```
```
### Set expression and BeanInfo caches to size 1000 with LRU cache mode
struts.ognl.enableExpressionCache=true
struts.ognl.expressionCacheMaxSize=1000
struts.ognl.expressionCacheLRUMode=true
struts.ognl.beanInfoCacheMaxSize=1000
struts.ognl.beanInfoCacheLRUMode=true
```

Below are some examples of setting the cache configuration via struts.xml:
```
<!-- Set expression and BeanInfo caches to size 1250 with standard cache mode -->
<constant name="struts.ognl.enableExpressionCache" value="true"/>
<constant name="struts.ognl.expressionCacheMaxSize" value="1250"/>
<constant name="struts.ognl.expressionCacheLRUMode" value="false"/>
<constant name="struts.ognl.beanInfoCacheMaxSize" value="1250"/>
<constant name="struts.ognl.beanInfoCacheLRUMode" value="false"/>
```
```
<!-- Set expression and BeanInfo caches to size 1000 with LRU cache mode -->
<constant name="struts.ognl.enableExpressionCache" value="true"/>
<constant name="struts.ognl.expressionCacheMaxSize" value="1000"/>
<constant name="struts.ognl.expressionCacheLRUMode" value="true"/>
<constant name="struts.ognl.beanInfoCacheMaxSize" value="1000"/>
<constant name="struts.ognl.beanInfoCacheLRUMode" value="true"/>
```

As of Struts 6.0.0, developers may choose to implement their own OGNL cache factories,
instead of using the default implementations, should they desire to. The default
implementations can be referenced to give an idea of how to implement a custom implementation.
For example, if a developer implements a CustomExpressionCacheFactory and CustomBeanInfoCacheFactory
that both implement the OgnlCacheFactory interface, they could be installed via
a configuration in struts.xml:
```
<constant name="struts.ognl.expressionCacheFactory" value="some.package.CustomExpressionCacheFactory"/>
<constant name="struts.ognl.beanInfoCacheFactory" value="some.package.CustomBeanInfoCacheFactory"/>
```
If the developer wants the standard configuration properties for the caches to function, they will need
to implement equivalent methods to the ones the default implementation uses to populate those properties.

Beyond the configuration properties, in certain circumstances, developers may choose to utilize certain methods to
interact with the OGNL caches. Refer to the API documentation for [OgnlUtil](https://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/ognl/OgnlUtil.html).