4

I am working with ehcache. I am caching Spring @Service method :

@Service( value = "dataServicesManager" )
@Transactional
public class DataServicesManager implements IDataServicesManager{

    @Autowired
    private IDataDAO dataDAO;



    @Override
    @Cacheable( value = "alldatas" )
    public List<Data> getAllDatas(Integer param) {

                // my logic

        return results;

    }
// others services
}

Here is the Spring configuration snippet:

 <cache:annotation-driven/>

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
    <property name="cacheManager" ref="ehcache"/>
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="WEB-INF/ehcache.xml"/>
    <property name="shared" value="true"/>
</bean>

Here is my ehcache configuration.

<ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">

<diskStore path="C:/TEMP/ehcache"/>

<defaultCache   eternal="false"
       timeToIdleSeconds="300"
       timeToLiveSeconds="1200"
       overflowToDisk="true"
       diskPersistent="false"
       diskExpiryThreadIntervalSeconds="120" />

<cache name="alldatas" maxEntriesLocalHeap="10000" eternal="false"
        timeToIdleSeconds="21600" timeToLiveSeconds="21600" memoryStoreEvictionPolicy="LRU">

    </cache>

</ehcache>

When i call the service method getAllDatas from a Spring @Controller the method is cached and the second time call retrieve the result stores in cache. What i don't understand is that i cannot find the <diskStore path="C:/TEMP/ehcache"/> specify in the ehcache.xml. So i have two questions :

Question 1: Why "C:/TEMP/ehcache" directory is not created ?

Question 2: Where is cached my service results ?

Pracede
  • 4,226
  • 16
  • 65
  • 110

2 Answers2

2

Your Ehcache configuration is to blame.

The defaultCache element will only be used when you create a cache programatically without specifying a configuration.

But you define explicitly your alldatas cache, without any disk options.

So your configuration needs to become:

<cache name="alldatas" maxEntriesLocalHeap="10000" eternal="false"
    timeToIdleSeconds="21600" timeToLiveSeconds="21600" memoryStoreEvictionPolicy="LRU"
    overflowToDisk="true"
    diskPersistent="false"
    diskExpiryThreadIntervalSeconds="120">

</cache> 

And then this cache will use the disk store.

If you do not plan on having other caches in your application, you can also remove the defaultCache element for clarity.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
0

Probably because your retrieved data does not overflow to disk. Caching is done in memory until some threshold is overpassed. Try to reduce the maxEntriesLocalHeap to something that you know is small enough for your data to overflow and see if the file is created.

gregdim
  • 2,031
  • 13
  • 15
  • thanks for your answer. I changed maxEntriesLocalHeap="2". And i call many times my service but always no directory created. – Pracede Nov 06 '14 at 13:50
  • As of Ehcache 2.6, all data will be present in the lowest tier, disk in this case - see [this answer](http://stackoverflow.com/a/23358936/18591) – Louis Jacomet Nov 07 '14 at 08:43