[ 
https://issues.apache.org/jira/browse/OFBIZ-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17620413#comment-17620413
 ] 

Jacques Le Roux commented on OFBIZ-6747:
----------------------------------------

Finally, I has a serious look at UtilCache. 

I wrote above:
bq.  CLHM is only used in 2 places: UtilCache and ServiceDispatcher classes. 
Moreover in UtilCache it's only really used OOTB by 
EntityPerformanceTest.groovy.
Actually last sentence is wrong. CLHM  in UtilCache is OOTB only used by 
UtilCacheTests class.

I traced it back. CLHM was put in UtilCache by Adam more than 10 years ago. I 
guess he used it on his side. It's not used OOTB apart that. And we have a 
problem with UtilCacheTests, because we can't cast Caffeine to a Map without 
using its asMap() method. So we get the errors below when running tests with 
OFBIZ-6747.patch applied, when all the rest is OK.

{noformat}
> Task :test

org.apache.ofbiz.base.util.cache.UtilCacheTests > testCreateUtilCache FAILED
    java.lang.ClassCastException at UtilCacheTests.java:216

org.apache.ofbiz.base.util.cache.UtilCacheTests > testPutIfAbsent FAILED
    java.lang.ClassCastException at UtilCacheTests.java:184

org.apache.ofbiz.base.util.cache.UtilCacheTests > testPutIfAbsentAndGet FAILED
    java.lang.ClassCastException at UtilCacheTests.java:184

org.apache.ofbiz.base.util.cache.UtilCacheTests > testExpire FAILED
    java.lang.ClassCastException at UtilCacheTests.java:184

org.apache.ofbiz.base.util.cache.UtilCacheTests > testSimple FAILED
    java.lang.ClassCastException at UtilCacheTests.java:184

org.apache.ofbiz.base.util.cache.UtilCacheTests > testChangeMemSize FAILED
    java.lang.ClassCastException at UtilCacheTests.java:184
for UtilCacheTests to
{noformat}

Only for these specific cases we would need to create a UtilCacheAsMap class to 
set the inner memoryTable as a Map using asMap() method.

Let's summarize the OOTB situation: because of maxInMemory parameter, UtilCache 
never uses CLHM (Caffeine in our case) but in UtilCacheTests

Here are the options:
# Using Caffeine, we create  a specific UtilCacheAsMap class, only to satisfy 
UtilCacheTests
# We remove both CLHM  from UtilCache and UtilCacheTests 
# We let things as they are

# is complicated for no OOTB gains, and I guess even for users (Adam no longer 
seems to worry about OFBiz)
# is cleaner but needs some work and could annoy some old users migration
# seems the best option to me

Here is the patch  [^OFBIZ-6747.patch] 

> Replace ConcurrentLinkedHashMap by Caffeine
> -------------------------------------------
>
>                 Key: OFBIZ-6747
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-6747
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework/base, framework/service
>    Affects Versions: Upcoming Branch
>            Reporter: Ben Manes
>            Assignee: Jacques Le Roux
>            Priority: Minor
>             Fix For: Upcoming Branch
>
>         Attachments: OFBIZ-6747.patch
>
>
> Similar to OFBIZ-3779, please consider upgrading the library used by 
> [UtilCache|https://github.com/apache/ofbiz/blob/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/cache/UtilCache.java]
>  (v1.2). The current version is 1.4.2 and is the last major release planned.
> The preferable alternative would be to upgrade to 
> [Caffeine|https://github.com/ben-manes/caffeine]. This is a Java 8 rewrite 
> based on what I've learned since developing CLHM and Guava's cache. As 
> expected it provides [superior 
> performance|https://github.com/ben-manes/caffeine/wiki/Benchmarks]. It also 
> provides a [near 
> optimal|https://github.com/ben-manes/caffeine/wiki/Efficiency] eviction 
> policy.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to