-
Notifications
You must be signed in to change notification settings - Fork 816
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
WW-5355 Integrate W-TinyLfu cache and use by default #766
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
74d2fdc
WW-5355 Use LRU cache by default
kusalk 5011a79
WW-5355 Prevent AtomicInteger being initialised to zero
kusalk 9527da5
WW-5355 Initial Caffeine cache implementation
kusalk 1573207
WW-5355 Fix eviction limit in LRU cache not being enforced
kusalk 6ff7e15
WW-5355 Update JavaDoc for basic and LRU cache
kusalk 9c932f2
WW-5355 Introduce new Struts constants and their defaults
kusalk bfb4df1
WW-5355 Unify bootstrap constant declaration
kusalk d245dc5
WW-5355 Introduce new cache type selection methods and deprecate prob…
kusalk 4700dca
WW-5355 Downgrade Caffeine version
kusalk 7463e1d
WW-5355 Fix interface and unit test bug
kusalk 28cc645
WW-5355 Address code smells
kusalk 793d383
WW-5355 Delegate deprecated constructor
kusalk 9be23d7
WW-5355 Extract constants into static final fields
kusalk 3d5beae
WW-5355 Declare bootstrap constants as final field instead
kusalk f314b45
WW-5355 Add since tags to StrutsConstants JavaDoc
kusalk 9dbea66
WW-5355 Amend Caffeine cache implementation
kusalk 7cded18
WW-5355 Rename cache types
kusalk 7afc772
WW-5355 Bootstrap using basic cache
kusalk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,52 +15,86 @@ | |
*/ | ||
package com.opensymphony.xwork2.ognl; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.apache.commons.lang3.BooleanUtils; | ||
|
||
/** | ||
* Default OGNL Cache factory implementation. | ||
* <p>Default OGNL Cache factory implementation.</p> | ||
* | ||
* Currently used for Expression cache and BeanInfo cache creation. | ||
* <p>Currently used for Expression cache and BeanInfo cache creation.</p> | ||
* | ||
* @param <Key> The type for the cache key entries | ||
* @param <Key> The type for the cache key entries | ||
* @param <Value> The type for the cache value entries | ||
*/ | ||
public class DefaultOgnlCacheFactory<Key, Value> implements OgnlCacheFactory<Key, Value> { | ||
|
||
private final AtomicBoolean useLRUCache = new AtomicBoolean(false); | ||
private final AtomicInteger cacheMaxSize = new AtomicInteger(25000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making this factory class thread-safe seemed unnecessary |
||
private static final int DEFAULT_INIT_CAPACITY = 16; | ||
private static final float DEFAULT_LOAD_FACTOR = 0.75f; | ||
|
||
private CacheType defaultCacheType; | ||
private int cacheMaxSize; | ||
|
||
/** | ||
* @deprecated since 6.4.0, use {@link #DefaultOgnlCacheFactory(int, CacheType)} | ||
*/ | ||
@Deprecated | ||
public DefaultOgnlCacheFactory() { | ||
this(10000, CacheType.BASIC); | ||
} | ||
|
||
public DefaultOgnlCacheFactory(int cacheMaxSize, CacheType defaultCacheType) { | ||
this.cacheMaxSize = cacheMaxSize; | ||
this.defaultCacheType = defaultCacheType; | ||
} | ||
|
||
@Override | ||
public OgnlCache<Key, Value> buildOgnlCache() { | ||
return buildOgnlCache(getCacheMaxSize(), 16, 0.75f, getUseLRUCache()); | ||
return buildOgnlCache(getCacheMaxSize(), DEFAULT_INIT_CAPACITY, DEFAULT_LOAD_FACTOR, defaultCacheType); | ||
} | ||
|
||
@Override | ||
public OgnlCache<Key, Value> buildOgnlCache(int evictionLimit, int initialCapacity, float loadFactor, boolean lruCache) { | ||
if (lruCache) { | ||
return new OgnlLRUCache<>(evictionLimit, initialCapacity, loadFactor); | ||
} else { | ||
return new OgnlDefaultCache<>(evictionLimit, initialCapacity, loadFactor); | ||
public OgnlCache<Key, Value> buildOgnlCache(int evictionLimit, | ||
int initialCapacity, | ||
float loadFactor, | ||
CacheType cacheType) { | ||
switch (cacheType) { | ||
case BASIC: | ||
return new OgnlDefaultCache<>(evictionLimit, initialCapacity, loadFactor); | ||
case LRU: | ||
return new OgnlLRUCache<>(evictionLimit, initialCapacity, loadFactor); | ||
case WTLFU: | ||
return new OgnlCaffeineCache<>(evictionLimit, initialCapacity); | ||
default: | ||
throw new IllegalArgumentException("Unknown cache type: " + cacheType); | ||
} | ||
} | ||
|
||
@Override | ||
public int getCacheMaxSize() { | ||
return cacheMaxSize.get(); | ||
return cacheMaxSize; | ||
} | ||
|
||
/** | ||
* @deprecated since 6.4.0 | ||
*/ | ||
@Deprecated | ||
protected void setCacheMaxSize(String maxSize) { | ||
cacheMaxSize.set(Integer.parseInt(maxSize)); | ||
cacheMaxSize = Integer.parseInt(maxSize); | ||
} | ||
|
||
@Override | ||
public boolean getUseLRUCache() { | ||
return useLRUCache.get(); | ||
public CacheType getDefaultCacheType() { | ||
return defaultCacheType; | ||
} | ||
|
||
/** | ||
* No effect when {@code useLRUMode} is {@code false} | ||
* | ||
* @deprecated since 6.4.0 | ||
*/ | ||
@Deprecated | ||
protected void setUseLRUCache(String useLRUMode) { | ||
useLRUCache.set(BooleanUtils.toBoolean(useLRUMode)); | ||
if (BooleanUtils.toBoolean(useLRUMode)) { | ||
defaultCacheType = CacheType.LRU; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted bootstrap constants into a public static final field for reuse by the default Struts configuration provider and any test code as needed. Adding new required constants was previously a pain