[ https://issues.apache.org/jira/browse/WW-5355?focusedWorklogId=885238&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-885238 ]
ASF GitHub Bot logged work on WW-5355: -------------------------------------- Author: ASF GitHub Bot Created on: 15/Oct/23 17:34 Start Date: 15/Oct/23 17:34 Worklog Time Spent: 10m Work Description: ben-manes commented on code in PR #766: URL: https://github.com/apache/struts/pull/766#discussion_r1359917925 ########## core/src/main/java/com/opensymphony/xwork2/ognl/OgnlCaffeineCache.java: ########## @@ -0,0 +1,82 @@ +/* + * Copyright 2022 Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.opensymphony.xwork2.ognl; + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; + +/** + * <p>This OGNL Cache implementation is backed by {@link Caffeine} which uses the Window TinyLfu algorithm.</p> + * + * <p>An appropriate eviction limit should be chosen for your specific application based on factors and requirements + * such as:</p> + * <ul> + * <li>Quantity and complexity of actions</li> + * <li>Volume of requests</li> + * <li>Rate limits and attack potential/patterns</li> + * <li>Memory constraints</li> + * </ul> + * + * @param <K> The type for the cache key entries + * @param <V> The type for the cache value entries + */ +public class OgnlCaffeineCache<K, V> implements OgnlCache<K, V> { + + private final Cache<K, V> cache; + private final int evictionLimit; + + public OgnlCaffeineCache(int evictionLimit, int initialCapacity) { + this.evictionLimit = evictionLimit; + this.cache = Caffeine.newBuilder().initialCapacity(initialCapacity).maximumSize(evictionLimit).build(); + } + + @Override + public V get(K key) { + return cache.getIfPresent(key); + } + + @Override + public void put(K key, V value) { + cache.put(key, value); + } + + @Override + public void putIfAbsent(K key, V value) { + if (cache.getIfPresent(key) == null) { + cache.put(key, value); + } Review Comment: `cache.asMap().putIfAbsent(key, value)` Issue Time Tracking ------------------- Worklog Id: (was: 885238) Time Spent: 5h (was: 4h 50m) > Use LRU cache by default > ------------------------ > > Key: WW-5355 > URL: https://issues.apache.org/jira/browse/WW-5355 > Project: Struts 2 > Issue Type: Improvement > Components: Core > Reporter: Kusal Kithul-Godage > Priority: Minor > Fix For: 6.4.0 > > Time Spent: 5h > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.20.10#820010)