title: Spring Ehcache not working
body: <p>I have implemented the declarative caching in my Spring MVC using ehcache.
  Below is code of Spring config.</p>
  
  <pre><code>&lt;cache:annotation-driven /&gt;
  
      &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"&gt;
              &lt;property name="cacheManager" ref="ehcache" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;
          &lt;property name="configLocation" value="classpath:ehcache.xml" /&gt;
          &lt;property name="shared" value="true"/&gt;
      &lt;/bean&gt;
  
  &lt;bean id="UserDaoImpl" class="org.kmsg.dao.impl.UserDaoImpl"&gt;
          &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Below is ehcache xml config.</p>
  
  <pre><code>&lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
      monitoring="autodetect" dynamicConfig="true"&gt;
      &lt;diskStore path="c:\\cache" /&gt;
  
      &lt;cache name="findUser"
          maxEntriesLocalHeap="10000"
          maxEntriesLocalDisk="1000"
          eternal="false"
          diskSpoolBufferSizeMB="20"
          timeToIdleSeconds="300" timeToLiveSeconds="600"
          memoryStoreEvictionPolicy="LFU"
          transactionalMode="off"&gt;
          &lt;persistence strategy="localTempSwap" /&gt;
      &lt;/cache&gt;
  
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>This is adapter class where i want to implement caching:</p>
  
  <pre><code>    public class LoginAdapter
      {
          static UserDaoImpl daoimpl =(UserDaoImpl)MainAdapter.context.getBean("UserDaoImpl");
  
          @Cacheable(value="findUser", key="#userId")
          public UserModel checkLogin1(String userId,String password)
          {
              UserModel   model = daoimpl.selectUserInfo(userId);         
  
              return model;
          }
  }
  </code></pre>
  
  <p>The User Dao code:</p>
  
  <pre><code>public class UserDaoImpl implements UserDaoInt
  {
          JdbcTemplate jdbc=new JdbcTemplate();
  
          @Override
          public void setDataSource(DataSource dataSource)
          {
              jdbc=new JdbcTemplate(dataSource);
          }
  
          @Override
          public UserModel selectUserInfo(String userId) 
          {
              String sql  =   "SELECT "
                      + "user_id, "
                      + "password, "
                      + "no_of_device, "
                      + "email_id, "
                      + "otp, "
                      + "approved, "
                      + "secret_code, "
                      + "os, "
                      + "version, "
                      + "version_name, "
                      + "mobile_maker, "
                      + "mobile_model "
                      + "FROM user "
                      + "WHERE user_id=?; ";
  
              System.out.println("calling......");
              return jdbc.queryForObject(sql,new Object[]{userId},new UserMapper());
          }
  }
  </code></pre>
  
  <p>And finally this is the service:</p>
  
  <pre><code>@RequestMapping(value="/login" , method = RequestMethod.POST, headers="Accept=application/json")
      public UserModel checkLogin1(@RequestParam Map&lt;String, String&gt; params)
      {
          String userid   =   params.get("userId");
          String password =   params.get("password");
  
          return adapter.checkLogin1(userid, password);
      }
  </code></pre>
  
  <p>When i run the project and call the service, everytime the data is called from database and not from cache. However the cache files are created at the specified place(c:\cache) but these files are empty.</p>
  
  <p>I could not find the problem. There is no error in logs. This is my first time of doing caching. Please help me on this.</p>
  
  <p>Thanks.</p>