本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}