Java 类org.springframework.cache.annotation.CachePut 实例源码

项目:Facegram    文件:AdministrativeServiceImpl.java   
@Override
@CachePut(cacheNames = "RetrieveGroup", key = "#groupId")
@HystrixCommand(fallbackMethod = "retrieveGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public Group retrieveGroup(String groupId) {
    Assert.hasLength(groupId, "retrieveGroup input is empty");
    Group group = groupRepository.findOne(groupId);
    if(group == null){
        logger.warn("No group with id={} was found.", groupId);
        return new Group();
    }
    return group;
}
项目:Facegram    文件:HotStoriesService.java   
@Override
@CachePut(cacheNames = "HotStoriesOfGroup", key = "#groupId")
@HystrixCommand(fallbackMethod = "hotStoriesOfGroupFallback", ignoreExceptions = IllegalArgumentException.class)
public List<Story> getStoriesOfGroup(String groupId) {
    Assert.hasLength(groupId, "Hot stories of group input was null or empty");
    return storyRepository.findHotStoriesOfGroup(groupId);
}
项目:Facegram    文件:AdministrativeServiceImpl.java   
@Override
@CachePut(cacheNames = "RetrieveGroupIds", key = "#username")
@HystrixCommand(fallbackMethod = "retrieveGroupIdsFallback", ignoreExceptions = IllegalArgumentException.class)
public List<String> retrieveGroupIds(String username) {
    Assert.hasLength(username, "retrieveGroupIds input is empty or null");
    if (!userRepository.exists(username)) {
        logger.warn("No user with id={} was found.", username);
        return new ArrayList<>();
    }

    List<String> followingGroupIds = userRepository.getGroupIdsByUsername(username).getFollowingGroupIds();
    return followingGroupIds;
}
项目:automat    文件:SysSessionService.java   
@CachePut
@Transactional
public SysSession update(SysSession record) {
    if (record != null && record.getId() == null) {
        record.setUpdateTime(new Date());
        Long id = ((SysSessionMapper) mapper).queryBySessionId(record.getSessionId());
        if (id != null) {
            mapper.updateById(record);
        } else {
            record.setCreateTime(new Date());
            mapper.insert(record);
        }
    } else {
        mapper.updateById(record);
    }
    return record;
}
项目:iBase4J    文件:SysSessionService.java   
@CachePut
@Transactional
public SysSession update(SysSession record) {
    if (record.getId() == null) {
        record.setUpdateTime(new Date());
        Long id = ((SysSessionMapper) mapper).queryBySessionId(record.getSessionId());
        if (id != null) {
            mapper.updateById(record);
        } else {
            record.setCreateTime(new Date());
            mapper.insert(record);
        }
    } else {
        mapper.updateById(record);
    }
    return record;
}
项目:JAVA-    文件:SysSessionService.java   
@CachePut
@Transactional
public SysSession update(SysSession record) {
    if (record != null && record.getId() == null) {
        record.setUpdateTime(new Date());
        Long id = ((SysSessionMapper) mapper).queryBySessionId(record.getSessionId());
        if (id != null) {
            mapper.updateById(record);
        } else {
            record.setCreateTime(new Date());
            mapper.insert(record);
        }
    } else {
        mapper.updateById(record);
    }
    return record;
}
项目:hsweb-framework    文件:SimpleOAuth2UserTokenService.java   
@Override
@Caching(
        put = @CachePut(cacheNames = "oauth2-user-token", key = "'a-t:'+#tokenInfo.accessToken"),
        evict = @CacheEvict(cacheNames = "oauth2-user-token-list", key = "'s-g-t:'+#result.serverId+':'+#result.grantType")
)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public AccessTokenInfo insert(AccessTokenInfo tokenInfo) {
    if (tokenInfo.getId() == null) {
        tokenInfo.setId(getIDGenerator().generate());
    }
    OAuth2UserTokenEntity entity = entityTokenInfoMapping().apply(tokenInfo);
    entity.setCreateTime(tokenInfo.getCreateTime());
    entity.setUpdateTime(tokenInfo.getUpdateTime());

    insert(entity);
    return tokenInfo;
}
项目:Qihua    文件:MemberCacheService.java   
@Caching(cacheable = {@Cacheable(value = "member", key = "\"Member.memberId:\" + #member.memberId")},
    put = {
        @CachePut(value = "member", key = "\"Member.memberName:\" + #result.memberName",
            condition = "#result != null"),
        @CachePut(value = "member", key = "\"Member.email:\" + #result.email", condition = "#result != null")})
// 将 memberName,email 作为 key 加入到缓存,以便于 findByMemberName,findByEmail 可以使用缓存
public Member findByMemberId(final Member member) {
  System.out.println("cache miss, invoke find by memberId, memberId:" + member.getMemberId());
  for (Member item : members) {
    if (item.getMemberId().equals(member.getMemberId())) {
      return item;
    }
  }

  return null;
}
项目:Spring-Boot-Blog    文件:UserServiceImpl.java   
@CachePut(value = USER_CACHE_NAME, key = "'user_cache_key'+#userLogin")
@Override
public User addUser(String userLogin, String userPass) throws UserException {
    if (StringUtils.isBlank(userLogin)) {
        throw new UserException("不合法的用户名!");
    } else if (StringUtils.isBlank(userPass)) {
        throw new UserException("不合法的密码!");
    }

    if (findByUserLogin(userLogin) != null) {
        throw new UserException("用户名已存在!");
    }

    User user = new User();
    user.setUserLogin(userLogin);
    user.setUserPass(userPass);
    user.setUserNiceName(userLogin);
    //TODO:此处待完善
    /**
     * 密码加盐并取MD5
     */
    PassWordUtil.fuckUser(user);
    return userRepo.save(user);
}
项目:Spring-Boot-Blog    文件:PostServiceImpl.java   
@CachePut(value = POST_CACHE_NAME, key = "'post_cache_key_'+#title")
@CacheEvict(value = PAGE_CACHE_NAME, allEntries = true)
@Override
public Post editPost(Long id, String title, String markdown, String html, List<String> tagStringList) throws Exception {
    if (id < 0) {
        throw new PostInputException("不存在的文章!");
    } else if (StringUtils.isBlank(title)) {
        throw new PostInputException("标题不可为空!");
    }
    Post tmpPost = postRepo.findByPostTitle(title);
    if (tmpPost != null && tmpPost.getId() != id) {
        throw new PostInputException("标题不能重复!");
    }

    Post post = postRepo.findOne(id);
    post.setUser(userSrv.getUser());
    post.setPostTitle(title);
    post.setPostContent(markdown);
    post.setPostShow(html);
    post.setTags(tagSrv.strListToTagList(tagStringList));

    return postRepo.save(post);
}
项目:Spring-Boot-Blog    文件:PostServiceImpl.java   
@CachePut(value = POST_CACHE_NAME, key = "'post_cache_key_'+#title")
@CacheEvict(value = PAGE_CACHE_NAME, allEntries = true)
@Override
public Post pushPost(String title, String markdown, String html, List<String> tagStringList, PostStatus postStatus) throws Exception {
    if (StringUtils.isBlank(title)) {
        throw new PostInputException("标题不能为空!");
    } else if (findByPostTitle(title) != null) {
        throw new PostInputException("标题不能重复!");
    }

    Post post = new Post();
    post.setUser(userSrv.getUser());
    post.setPostStatus(postStatus);
    post.setPostTitle(title);
    post.setPostContent(markdown);
    post.setPostShow(html);
    post.setTags(tagSrv.strListToTagList(tagStringList));

    return postRepo.save(post);
}
项目:springsecuredthymeleafapp    文件:SecurityServiceImpl.java   
/** {@inheritDoc} */
@Override
@Caching(evict = { @CacheEvict(value = "users", allEntries = true) }, put = {
        @CachePut(value = "user", key = "#id") })
public User updateUser(User user, String id) throws SecuredAppException {
    User persistedUser = getUserById(id);
    if (persistedUser == null) {
        throw new SecuredAppException("User " + user.getId() + " doesn't exist");
    }

    // List<Role> updatedRoles = new ArrayList<>();
    List<Role> updatedRoles = user.getRoleList().stream().parallel()
            .filter(role -> role.getId() != null)
            .map(role -> getRoleById(role.getId()))
            .collect(Collectors.toCollection(ArrayList::new));
    /*
     * if(roles != null){ for (Role role : roles) { if(role.getId() != null)
     * { updatedRoles.add(getRoleById(role.getId())); } } }
     */
    persistedUser.setRoleList(updatedRoles);
    return userRepository.save(persistedUser);
}
项目:skeleton-ws-spring-boot    文件:GreetingServiceBean.java   
@CachePut(value = Application.CACHE_GREETINGS,
        key = "#result.id")
@Transactional
@Override
public Greeting create(final Greeting greeting) {
    logger.info("> create");

    counterService.increment("method.invoked.greetingServiceBean.create");

    // Ensure the entity object to be created does NOT exist in the
    // repository. Prevent the default behavior of save() which will update
    // an existing entity if the entity matching the supplied id exists.
    if (greeting.getId() != null) {
        logger.error("Attempted to create a Greeting, but id attribute was not null.");
        logger.info("< create");
        throw new EntityExistsException(
                "Cannot create new Greeting with supplied id.  The id attribute must be null to create an entity.");
    }

    final Greeting savedGreeting = greetingRepository.save(greeting);

    logger.info("< create");
    return savedGreeting;
}
项目:skeleton-ws-spring-boot    文件:GreetingServiceBean.java   
@CachePut(value = Application.CACHE_GREETINGS,
        key = "#greeting.id")
@Transactional
@Override
public Greeting update(final Greeting greeting) {
    logger.info("> update {}", greeting.getId());

    counterService.increment("method.invoked.greetingServiceBean.update");

    // Ensure the entity object to be updated exists in the repository to
    // prevent the default behavior of save() which will persist a new
    // entity if the entity matching the id does not exist
    final Greeting greetingToUpdate = findOne(greeting.getId());
    if (greetingToUpdate == null) {
        logger.error("Attempted to update a Greeting, but the entity does not exist.");
        logger.info("< update {}", greeting.getId());
        throw new NoResultException("Requested Greeting not found.");
    }

    greetingToUpdate.setText(greeting.getText());
    final Greeting updatedGreeting = greetingRepository.save(greetingToUpdate);

    logger.info("< update {}", greeting.getId());
    return updatedGreeting;
}
项目:simple-spring-memcached    文件:AppUserDAOImpl.java   
@Override
@CachePut(value = USER_CACHE_NAME, key = "#entity.cacheKey()")
public AppUser update(final AppUser entity) {
    AppUser appUser = entity;
    MAP.put(entity.getPK(), entity);
    List<AppUser> list = USER_ID_MAP.get(entity.getUserId());
    if (list == null) {
        list = new ArrayList<AppUser>();
        USER_ID_MAP.put(entity.getUserId(), list);
    }
    list.add(entity);

    assert appUser.getApplicationId() == entity.getApplicationId();
    assert appUser.getUserId() == entity.getUserId();

    return appUser;
}
项目:arsnova-backend    文件:ContentServiceImpl.java   
@Override
@Caching(evict = {@CacheEvict(value = "contentlists", key = "#sessionId"),
        @CacheEvict(value = "lecturecontentlists", key = "#sessionId", condition = "#content.getQuestionVariant().equals('lecture')"),
        @CacheEvict(value = "preparationcontentlists", key = "#sessionId", condition = "#content.getQuestionVariant().equals('preparation')"),
        @CacheEvict(value = "flashcardcontentlists", key = "#sessionId", condition = "#content.getQuestionVariant().equals('flashcard')") },
        put = {@CachePut(value = "contents", key = "#content.id")})
public Content save(final String sessionId, final Content content) {
    content.setSessionId(sessionId);
    try {
        contentRepository.save(content);

        return content;
    } catch (final IllegalArgumentException e) {
        logger.error("Could not save content {}.", content, e);
    }

    return null;
}
项目:arsnova-backend    文件:SessionServiceImpl.java   
@CachePut(value = "sessions")
private Session updateSessionOwnerActivity(final Session session) {
    try {
        /* Do not clutter CouchDB. Only update once every 3 hours. */
        if (session.getLastOwnerActivity() > System.currentTimeMillis() - 3 * 3600000) {
            return session;
        }

        session.setLastOwnerActivity(System.currentTimeMillis());
        save(session);

        return session;
    } catch (final UpdateConflictException e) {
        logger.error("Failed to update lastOwnerActivity for session {}.", session, e);
        return session;
    }
}
项目:busi-support    文件:BusiSupportCacheService.java   
/**
 * 更新数据库的值,并更新redis的值
 *
 * @param paraCode  code
 * @param paraValue value
 * @return 更新后的值
 */
@CachePut(value = "mysql:busiSupportCacheService:commSysPara", key = "#paraCode")
public String updCommSysParaValue(String paraCode, String paraValue) {
    CommSysPara para = new CommSysPara();
    para.setSysParaValue(paraValue);
    para.setSysUpdTime(new Date());
    CommSysParaExample example = new CommSysParaExample();
    example.createCriteria().andSysParaCodeEqualTo(paraCode);
    commSysParaMapper.updateByExampleSelective(para, example);
    return paraValue;
}
项目:busi-support    文件:BusiSupportCacheService.java   
@CachePut(value = "mysql:busiSupportCacheService:omsCommSysPara", key = "#paraCode")
public String updOmsCommSysParaValue(String paraCode, String paraValue) {
    OmsCommSysPara para = new OmsCommSysPara();
    para.setSysParaValue(paraValue);
    para.setSysUpdTime(new Date());
    OmsCommSysParaExample example = new OmsCommSysParaExample();
    example.createCriteria().andSysParaCodeEqualTo(paraCode);
    omsCommSysParaMapper.updateByExampleSelective(para, example);
    return paraValue;
}
项目:iBase4J-Common    文件:SchedulerService.java   
@Transactional
@CachePut("taskFireLog")
public TaskFireLog updateLog(TaskFireLog record) {
    if (record.getId() == null) {
        logMapper.insert(record);
    } else {
        logMapper.updateById(record);
    }
    return record;
}
项目:springboot-learning-example    文件:CityServiceImpl.java   
@CachePut(value = "baseCityInfo")
public void updateCityDescription(String cityName, String description){
    City city = cityMap.get(cityName);
    city.setDescription(description);
    // 模拟更新数据库
    cityMap.put(cityName, city);
}
项目:Facegram    文件:HotStoriesService.java   
@Override
@CachePut(cacheNames = "HotStoriesOfLocation", key = "#geolocation")
@HystrixCommand(fallbackMethod = "hotStoriesOfLocationFallback", ignoreExceptions = IllegalArgumentException.class)
public List<Story> getStoriesOfLocation(Geolocation geolocation) {
    Assert.notNull(geolocation,"Hot stories of location input is null");
    return  storyRepository.findHotStoriesOfLocation(geolocation);
}
项目:Facegram    文件:HotStoriesService.java   
@Override
@CachePut(cacheNames = "HotStoriesOfUser", key = "#userId")
@HystrixCommand(fallbackMethod = "hotStoriesOfUserFallback", ignoreExceptions = IllegalArgumentException.class )
public List<Story> getStoriesOfUser(String userId) {
    Assert.hasLength(userId, "Hot stories of user input was null or empty");
    return  storyRepository.findHotStoriesOfUser(userId);
}
项目:Facegram    文件:AdministrativeServiceImpl.java   
@Override
@CachePut(cacheNames = "RetrieveMyGroups", key = "#username")
@HystrixCommand(fallbackMethod = "retrieveMyGroupsFallback", ignoreExceptions = IllegalArgumentException.class)
public List<Group> retrieveMyGroups(String username) {
    Assert.hasLength(username, "retrieveMyGroups input is empty");
    List<Group> groups = groupRepository.findByModerator(username);
    if(groups == null){
        logger.warn("No group for username={} was found.", username);
        return new ArrayList<>();
    }
    return groups;
}
项目:Facegram    文件:AdministrativeServiceImpl.java   
@Override
@CachePut(cacheNames = "RetrieveFollowings", key = "#username")
@HystrixCommand(fallbackMethod = "retrieveFollowingsFallback", ignoreExceptions = IllegalArgumentException.class)
public List<User> retrieveFollowings(String username) {
    Assert.hasLength(username, "retrieveFollowings input is empty or null");

    User user = userRepository.findByUsername(username);
    if (user == null) {
        logger.warn("No user with id={} was found.", username);
        return new ArrayList<>();
    }

    Iterable<User> friends = userRepository.findAll(user.getFollowingIds());
    return Lists.newArrayList(friends);
}
项目:automat    文件:SchedulerService.java   
@Transactional
@CachePut("taskFireLog")
public TaskFireLog updateLog(TaskFireLog record) {
    if (record.getId() == null) {
        logMapper.insert(record);
    } else {
        logMapper.updateById(record);
    }
    return record;
}
项目:springboot-learning-example-master    文件:CityServiceImpl.java   
@CachePut(value = "baseCityInfo")
public void updateCityDescription(String cityName, String description){
    City city = cityMap.get(cityName);
    city.setDescription(description);
    // 模拟更新数据库
    cityMap.put(cityName, city);
}
项目:iBase4J    文件:SchedulerService.java   
@Transactional
@CachePut("taskFireLog")
public TaskFireLog updateLog(TaskFireLog record) {
    if (record.getId() == null) {
        logMapper.insert(record);
    } else {
        logMapper.updateById(record);
    }
    return record;
}
项目:microservices-event-sourcing    文件:UserService.java   
@CachePut(value = "user", key = "#id")
public User updateUser(Long id, User user) {
    User result = null;
    if(userRepository.exists(user.getId())) {
        result = userRepository.save(user);
    }
    return result;
}
项目:stuffEngine    文件:HibernateDepartmentDao.java   
@Override
@Caching(evict ={@CacheEvict(cacheNames = "subdepts", allEntries = true, beforeInvocation = true)},
        put = {@CachePut(cacheNames = "department", key = "#department.id")})
public Department updateDept(Department department) {
    logger.info("Запрос к базе на изменение отдела c ID: " + department.getId());
    Session session = getSession();
    try{
        session.update(department);
    }catch (HibernateException e){
        logger.error(e.getStackTrace());
        throw new MyRuntimeException(StuffExceptions.DATABASE_ERROR);
    }
    return readById(department.getId());
}
项目:microservices-sample-project    文件:GenericDaoImpl.java   
@Override
@Caching(
            put={@CachePut(key="#object.id")},
            evict={@CacheEvict(cacheResolver="secondaryCacheResolver", allEntries=true)}
        )
public T add(T object) throws DataAccessException {
    if (logger.isDebugEnabled())
        logger.debug("type {} add", type);
    try {
        mongoOperations.insert(object);
        return object;
    } catch (Exception e) {
        throw new DataAccessException(e);
    }
}
项目:microservices-sample-project    文件:GenericDaoImpl.java   
@Override
@Caching(
        put={@CachePut(key="#object.id")},
        evict={@CacheEvict(cacheResolver="secondaryCacheResolver", allEntries=true)}
        )
public T modify(T object) throws DataAccessException {
    if (logger.isDebugEnabled())
        logger.debug("type {} modify", type);
    try {
        mongoOperations.save(object);
        return object;
    } catch (Exception e) {
        throw new DataAccessException(e);
    }
}
项目:pokemon    文件:GenericDaoImpl.java   
@Override
@Caching(
            put={@CachePut(key="#object.id")},
            evict={@CacheEvict(cacheResolver="secondaryCacheResolver", allEntries=true)}
        )
public T add(T object) throws DataAccessException {
    if (logger.isDebugEnabled())
        logger.debug("type {} add", type);
    try {
        mongoOperations.insert(object);
        return object;
    } catch (Exception e) {
        throw new DataAccessException(e);
    }
}
项目:pokemon    文件:GenericDaoImpl.java   
@Override
@Caching(
        put={@CachePut(key="#object.id")},
        evict={@CacheEvict(cacheResolver="secondaryCacheResolver", allEntries=true)}
        )
public T modify(T object) throws DataAccessException {
    if (logger.isDebugEnabled())
        logger.debug("type {} modify", type);
    try {
        mongoOperations.save(object);
        return object;
    } catch (Exception e) {
        throw new DataAccessException(e);
    }
}
项目:JAVA-    文件:SchedulerService.java   
@Transactional
@CachePut("taskFireLog")
public TaskFireLog updateLog(TaskFireLog record) {
    if (record.getId() == null) {
        logMapper.insert(record);
    } else {
        logMapper.updateById(record);
    }
    return record;
}
项目:FCat    文件:LoginUserServiceImpl.java   
@Override
@CachePut(key = "#p0", value = "loginUser")
public LoginUser saveLoginUser(String userName, String password) {
    LoginUser loginUser = new LoginUser();
    loginUser.setUserName(userName);
    loginUser.setPassword(password);
    return loginUser;
}
项目:springbootWeb    文件:CommSysParaServiceImpl.java   
/**
 * 更新数据库的值,并更新redis的值
 *
 * @param paraCode  code
 * @param paraValue value
 * @return 更新后的值
 */
@CachePut(value = "mysql:commSysParaMapper:commSysPara", key = "#paraCode")
@Override
public String updCommSysParaValue(String paraCode, String paraValue) {
    CommSysPara para = new CommSysPara();
    para.setSysParaValue(paraValue);
    para.setSysUpdTime(new Date());
    CommSysParaExample example = new CommSysParaExample();
    example.createCriteria().andSysParaCodeEqualTo(paraCode);
    commSysParaMapper.updateByExampleSelective(para, example);
    return paraValue;
}
项目:vkmusic    文件:DefaultPropertyService.java   
@CachePut(key = "#properties.class")
@Override
public <T extends Properties> T set(T properties) {
    Property entity = new Property(properties.getClass().getSimpleName(), JsonUtils.toString(properties));
    propertyRepository.save(entity);
    return properties;
}
项目:hsweb-framework    文件:SimpleAccessTokenService.java   
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Caching(put = {
        @CachePut(cacheNames = "oauth2-access-token", key = "'refresh:'+#result.refreshToken"),
        @CachePut(cacheNames = "oauth2-access-token", key = "'token:'+#result.accessToken"),
        @CachePut(cacheNames = "oauth2-access-token", key = "'cgo'+#result.clientId+#result.grantType+#result.ownerId")
})
public OAuth2AccessToken saveOrUpdateToken(OAuth2AccessToken token) {
    Assert.notNull(token, "token can not be null!");
    int total = DefaultDSLQueryService
            .createQuery(oAuth2AccessDao)
            .where("clientId", token.getClientId())
            .and("grantType", token.getGrantType())
            .and("ownerId", token.getOwnerId()).total();
    token.setUpdateTime(System.currentTimeMillis());
    if (total > 0) {
        DefaultDSLUpdateService
                .createUpdate(oAuth2AccessDao, token)
                .where("clientId", token.getClientId())
                .and("grantType", token.getGrantType())
                .and("ownerId", token.getOwnerId())
                .exec();
    } else {
        token.setCreateTime(System.currentTimeMillis());
        oAuth2AccessDao.insert(((OAuth2AccessEntity) token));
    }

    return token;
}
项目:hsweb-framework    文件:SimpleOAuth2UserTokenService.java   
@Override
@Caching(
        put = @CachePut(cacheNames = "oauth2-user-token", key = "'a-t:'+#tokenInfo.accessToken"),
        evict = @CacheEvict(cacheNames = "oauth2-user-token-list", key = "'s-g-t:'+#result.serverId+':'+#result.grantType")
)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public AccessTokenInfo update(String id, AccessTokenInfo tokenInfo) {
    OAuth2UserTokenEntity entity = entityTokenInfoMapping().apply(tokenInfo);
    entity.setUpdateTime(System.currentTimeMillis());
    updateByPk(id, entity);
    return tokenInfo;
}