ehcache / ehcache3

Ehcache 3.x line
http://www.ehcache.org
Apache License 2.0
2.01k stars 579 forks source link

Disk store cache is not working #2744

Closed kapilmaheshwari closed 1 year ago

kapilmaheshwari commented 4 years ago

Hi,

Problem Statement: I have to compare two TreeSet which have a millions of records.

Solution I have used ehcache 3 with spring boot to store the data over the disk.

Implementation 1) Jars compile("org.springframework.boot:spring-boot-starter-cache") compile("javax.cache:cache-api") compile("org.ehcache:ehcache:3.7.1") 2) ehcache.xml

<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.ehcache.org/v3' xsi:schemaLocation=" http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.7.xsd">

<!-- Persistent cache directory -->
<persistence directory="/tmp/application/cache" />

<!-- Default cache template -->
<cache-template name="default">
    <expiry>
        <ttl unit="seconds">100</ttl>
    </expiry>

    <resources>
        <heap unit="GB">15</heap>
        <disk persistent="true" unit="GB">30</disk>
    </resources>
</cache-template>

<cache alias="cache1" uses-template="default">
    <key-type>java.lang.String</key-type>
    <value-type>java.util.TreeSet</value-type>
</cache>

<cache alias="cache2" uses-template="default">
    <key-type>java.lang.String</key-type>
    <value-type>java.util.TreeSet</value-type>
</cache>

3) Classes

public class MyService {

@Autowired
 private CacheHelper cacheHelper;

 public void compare() {
     TreeSet<Record> record1 = new TreeSet<>();
     TreeSet<Record> record2 = new TreeSet<>();

    record1 = cacheHelper.getRecordsFromSource1(name);
    record2 = cacheHelper.getRecordsFromSource2(name);

    Set<Record> recordsDiff = Sets.difference(record1 , record2);

   .......
 }


I can see the folders created under the "/tmp/application/cache" but when I run the application and do the test, the memory of the application getting increase while the folder size remain same.
chrisdennis commented 1 year ago

The cache is configured with 15GB of heap and 30GB of disk. Assuming the cache isn't (aggressively) prematurely evicting, and the heap usage doesn't rise beyond 15GB then I don't see what the malfunction is.