@Cacheable(
     value = UserEmailPreferenceRule.USER_EMAIL_PREF_RULE_CACHE_REGION,
     key = "{#root.methodName,#userId}")
 public List<UserEmailPreferenceRuleDto> findRulesForUser(String userId) {
   List<UserEmailPreferenceRuleDto> res = new ArrayList();
   TypedQuery<UserEmailPreferenceRule> query =
       em.createQuery(
           "from "
               + UserEmailPreferenceRule.class.getCanonicalName()
               + " where userId=:userIdParam",
           UserEmailPreferenceRule.class);
   query.setParameter("userIdParam", userId);
   for (UserEmailPreferenceRule entity : query.getResultList()) {
     UserEmailPreferenceRuleDto obj =
         mapper.map(entity.getEmailPreferenceRule(), UserEmailPreferenceRuleDto.class);
     obj.setId(entity.getId());
     res.add(obj);
   }
   return res;
 }
 @Caching(
     evict = {
       @CacheEvict(
           value = UserEmailPreferenceRule.USER_EMAIL_PREF_RULE_CACHE_REGION,
           allEntries = true),
       @CacheEvict(value = Email.EMAILS_CACHE_KEY, allEntries = true)
     })
 public UserEmailPreferenceRule save(String userId, String ruleId) {
   UserEmailPreferenceRule entity = new UserEmailPreferenceRule();
   if (Strings.isNullOrEmpty(userId)) {
     entity.setUserId(SecurityContextHolder.getContext().getAuthentication().getName());
   } else {
     entity.setUserId(userId);
   }
   if (findRuleForUser(entity.getUserId(), ruleId) != null) {
     return findRuleForUser(entity.getUserId(), ruleId);
   }
   entity.setEmailPreferenceRule(EmailPreferenceRuleDao.instance().find(ruleId));
   return em.merge(entity);
 }