當前位置: 首頁>>代碼示例>>Java>>正文


Java CachePut類代碼示例

本文整理匯總了Java中org.springframework.cache.annotation.CachePut的典型用法代碼示例。如果您正苦於以下問題:Java CachePut類的具體用法?Java CachePut怎麽用?Java CachePut使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CachePut類屬於org.springframework.cache.annotation包,在下文中一共展示了CachePut類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: retrieveGroup

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:nicolasmanic,項目名稱:Facegram,代碼行數:13,代碼來源:AdministrativeServiceImpl.java

示例2: getStoriesOfGroup

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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);
}
 
開發者ID:nicolasmanic,項目名稱:Facegram,代碼行數:8,代碼來源:HotStoriesService.java

示例3: retrieveGroupIds

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:nicolasmanic,項目名稱:Facegram,代碼行數:14,代碼來源:AdministrativeServiceImpl.java

示例4: update

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:18,代碼來源:SysSessionService.java

示例5: update

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:18,代碼來源:SysSessionService.java

示例6: insert

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:18,代碼來源:SimpleOAuth2UserTokenService.java

示例7: findByMemberId

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:nickevin,項目名稱:Qihua,代碼行數:17,代碼來源:MemberCacheService.java

示例8: addUser

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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);
}
 
開發者ID:sheepmen,項目名稱:Spring-Boot-Blog,代碼行數:25,代碼來源:UserServiceImpl.java

示例9: editPost

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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);
}
 
開發者ID:sheepmen,項目名稱:Spring-Boot-Blog,代碼行數:24,代碼來源:PostServiceImpl.java

示例10: pushPost

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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);
}
 
開發者ID:sheepmen,項目名稱:Spring-Boot-Blog,代碼行數:21,代碼來源:PostServiceImpl.java

示例11: updateUser

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
/** {@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);
}
 
開發者ID:rajadilipkolli,項目名稱:springsecuredthymeleafapp,代碼行數:23,代碼來源:SecurityServiceImpl.java

示例12: create

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:leanstacks,項目名稱:skeleton-ws-spring-boot,代碼行數:25,代碼來源:GreetingServiceBean.java

示例13: update

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:leanstacks,項目名稱:skeleton-ws-spring-boot,代碼行數:26,代碼來源:GreetingServiceBean.java

示例14: update

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:ragnor,項目名稱:simple-spring-memcached,代碼行數:18,代碼來源:AppUserDAOImpl.java

示例15: save

import org.springframework.cache.annotation.CachePut; //導入依賴的package包/類
@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;
}
 
開發者ID:thm-projects,項目名稱:arsnova-backend,代碼行數:19,代碼來源:ContentServiceImpl.java


注:本文中的org.springframework.cache.annotation.CachePut類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。