customCacheResolver code example

Example 1: customCacheResolver

// Use key: id of location
  @Cacheable(value = "concerts", key = "#location.id", cacheManager = "gemfireCacheManager")
  public List<Concert> findConcerts(Location location) {
      ...
  }

  // key: hashCode of location
  @Cacheable(value = "concerts", key = "T(someType).hash(#location)", cacheResolver = "myOwnCacheResolver")
  public List<Concert> findConcerts(Location location) {
      ...
  }

  // conditional caching if location is in Dallas in operating.
  @Cacheable(value = "concerts", condition = "#location.city == 'Dallas'", unless = "#location.outOfBusiness")
  public List<Concert> findConcerts(Location location) {
      ...
  }

  // key: generated id of result
  @Cacheable(value = "concerts", key = "#result.id") 
  public Location saveLocation(Location location) {
      ...
  }

Example 2: customCacheResolver

@Cacheable(value = "user-cache", key="#userSearchVO.name", condition="#supportUser == false")
  public User findUser(UserSearchVO userSearchVO, boolean supportUser)
  {
      User foundUser = null;
      ...
      ...
      ...
      return foundUser;
  }

Tags:

Php Example