title: how to update cache in java spring framework on creating new entry
body: <p>Create user function:    </p>
  
  <pre><code>@Autowired private org.springframework.cache.CacheManager cacheManager;
  public boolean createUser(Users user,HttpSession session) {
      System.out.println("cache update changed");
      Cache c = cacheManager.getCache("defaultCache");
      if (c != null) {
          System.out.println("hello");
          c.put("",user.getUsername()); 
          // this code is not working 
      }
  
      //BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(user);
  
      MapSqlParameterSource params=new MapSqlParameterSource();
      params.addValue("username", user.getUsername());
      params.addValue("user_session_id", session.getId());
      java.util.Date today = new java.util.Date();
      //params.addValue("message_time",new java.sql.Timestamp(today.getTime()));
  
      params.addValue("user_last_activity_time", new java.sql.Timestamp(today.getTime()));
  
      jdbc.update("insert into users (username,user_session_id,user_last_activity_time) values (:username,:user_session_id,:user_last_activity_time)", params);// == 1;
  
      //c.clear();
      //return user;
      return true;
  }
  </code></pre>
  
  <p>Get user function:</p>
  
  <pre><code>@Cacheable(value="defaultCache")
  //@CachePut(value="defaultCache")
  public List&lt;Users&gt; getOnlineUsers() {
      System.out.println("DB Query");
      return jdbc.query(sql, new RowMapper&lt;Users&gt;() {
          @Override
          public Users mapRow(ResultSet rs, int rowNumb) throws SQLException {
              Users user = new Users();
              user.setId(rs.getInt("id"));
              user.setUsername(rs.getString("username"));
              return user;
          }
      });
  }
  </code></pre>
  
  <p>please help me how can I update the cache on creating new user so when I get users from <code>List&lt;Users&gt; getOnlineUsers()</code> function by jquery json function i should get updated cache. Thanks</p>