Search code examples
javaehcacheehcache-3

Write cached data of Ehcache to local file(disk) after server start and on restart data should be picked up from file(disk)


I am creating a cache on server startup(server startup is taking 10 minutes everytime).Currently I am using the in memory caching(of Ehcache).Now I want to build a mechanism so that once the data is cached I should be able to start the server within few seconds.Something like writing a persistent copy of the cache to file and on restart it should pick up cache from that file. [let me know if question is not clear.]. I am expecting the solution in java.

<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.xsd" >

<cache alias="testData" >

    <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>
    <resources>
        <heap unit="entries">5000</heap>
        <offheap unit="MB">50</offheap>
        
    </resources>
</cache></config>

I am using above xml.Suggest changes in this xml?


Solution

  • The disk tier of Ehcache should be able to help in this case. Note that you will have to resolve the question of stale data if these are not reference data that never expire.

    Have a look at the documentation on how to set this up.