当前位置: 首页>>代码示例>>Java>>正文


Java CacheEvict类代码示例

本文整理汇总了Java中org.springframework.cache.annotation.CacheEvict的典型用法代码示例。如果您正苦于以下问题:Java CacheEvict类的具体用法?Java CacheEvict怎么用?Java CacheEvict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CacheEvict类属于org.springframework.cache.annotation包,在下文中一共展示了CacheEvict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDownloadUsage

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
/**
 * Saves persistently a download performed by a user.
 *
 * @param size       download size.
 * @param start_date date downloading start.
 * @param user       associate user to download.
 */
@Transactional
@Caching (evict = {
   @CacheEvict (value = "network_download_count", key = "#user.getUUID ()", condition = "#user != null"),
   @CacheEvict (value = "network_download_size", key = "#user.getUUID ()", condition = "#user != null") })
public void createDownloadUsage (final Long size, final Date start_date,
      final User user)
{
   if (size == null || size < 0 || start_date == null || user == null)
   {
      throw new IllegalArgumentException ("Invalid parameters");
   }

   NetworkUsage download_usage = new NetworkUsage ();
   download_usage.setSize (size);
   download_usage.setDate (start_date);
   download_usage.setUser (user);
   download_usage.setIsDownload (true);
   networkUsageDao.create (download_usage);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:27,代码来源:NetworkUsageService.java

示例2: removeUnprocessed

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
@CacheEvict (
   value = { "product_count", "product", "products" },
            allEntries = true )
public void removeUnprocessed()
{
   long start = System.currentTimeMillis();

   Iterator<Product> products = getUnprocessedProducts();
   while (products.hasNext())
   {
      Product product = products.next();
      if (product != null)
      {
         products.remove();
      }
   }

   LOGGER.debug("Cleanup incomplete processed products in " + (System.currentTimeMillis() - start) + "ms");
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:21,代码来源:ProductService.java

示例3: resetPassword

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Transactional (readOnly=false, propagation=Propagation.REQUIRED)
@Caching (evict = {
   @CacheEvict(value = "user", allEntries = true),
   @CacheEvict(value = "userByName", allEntries = true)})
public void resetPassword(String code, String new_password)
   throws RootNotModifiableException, RequiredFieldMissingException, 
      EmailNotSentException
{
   User u = userDao.getUserFromUserCode (code);
   if (u == null)
   {
      throw new UserNotExistingException ();
   }
   checkRoot (u);

   u.setPassword (new_password);

   checkRequiredFields (u);
   userDao.update (u);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:21,代码来源:UserService.java

示例4: selfUpdateUser

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
/**
 * Update given User, after checking required fields.
 * 
 * @param user
 * @throws RootNotModifiableException
 * @throws RequiredFieldMissingException
 */
@PreAuthorize ("isAuthenticated ()")
@Transactional (readOnly=false, propagation=Propagation.REQUIRED)
@Caching (evict = {
   @CacheEvict(value = "user", key = "#user.getUUID ()"),
   @CacheEvict(value = "userByName", key = "#user.username.toLowerCase()")})
public void selfUpdateUser (User user) throws RootNotModifiableException,
   RequiredFieldMissingException, EmailNotSentException
{
   User u = userDao.read (user.getUUID ());
   checkRoot (u);
   u.setEmail (user.getEmail ());
   u.setFirstname (user.getFirstname ());
   u.setLastname (user.getLastname ());
   u.setAddress (user.getAddress ());
   u.setPhone (user.getPhone ());    
   u.setCountry (user.getCountry ());
   u.setUsage (user.getUsage ());
   u.setSubUsage (user.getSubUsage ());
   u.setDomain (user.getDomain ());
   u.setSubDomain (user.getSubDomain ());  

   checkRequiredFields (u);
   userDao.update (u);
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:32,代码来源:UserService.java

示例5: removeProducts

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@PreAuthorize ("hasRole('ROLE_DATA_MANAGER')")
@Transactional (readOnly=false, propagation=Propagation.REQUIRED)
@CacheEvict (value = "products", allEntries = true)
public void removeProducts (String uuid, Long[] pids)
{
   collectionDao.removeProducts (uuid, pids, null);
   long start = new Date ().getTime ();
   for (Long pid: pids)
   {
      try
      {
         searchService.index(productDao.read(pid));
      }
      catch (Exception e)
      {
         throw new RuntimeException("Cannot update Solr index", e);
      }
   }
   long end = new Date ().getTime ();
   LOGGER.info("[SOLR] Remove " + pids.length +
      " product(s) from collection spent " + (end-start) + "ms" );
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:23,代码来源:CollectionService.java

示例6: systemAddProduct

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Transactional (readOnly=false, propagation=Propagation.REQUIRED)
@CacheEvict (value = "products", allEntries = true)
public void systemAddProduct (String uuid, Long pid, boolean followRights)
{
   Collection collection = collectionDao.read (uuid);
   Product product = productDao.read (pid);

   this.addProductInCollection(collection, product);
   try
   {
      searchService.index(product);
   }
   catch (Exception e)
   {
      throw new RuntimeException("Cannot update Solr index", e);
   }
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:18,代码来源:CollectionService.java

示例7: insertOneArticle

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Override
@Transactional(rollbackFor = Exception.class)
@Caching(evict = {
        @CacheEvict(value = "getOneArticleById", key =  "#root.target.oneArticleKey + #article.id"),
        @CacheEvict(value = "getArticlesCount", key = "#root.target.articleCountKey + #username")
})
public long insertOneArticle(Article article) {
    long articleId = idWorker.nextId();
    article.setId(articleId);
    article.setCreatedTime(new Date());  // add the created time
    article.setModifiedTime(new Date());  // add the modified time

    articleMapper.insertOneArticle(article);

    logger.info(article.getUsername() + " insert article " + article.getId() + " successfully");

    deleteAllPagesCache(article.getUsername());

    return articleId;
}
 
开发者ID:ziwenxie,项目名称:leafer,代码行数:21,代码来源:ArticleServiceImpl.java

示例8: insertOneTag

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = "getAllTags", key = "#root.target.allTagsKey + #username")
public Tag insertOneTag(String tagName, String username) {
    Tag isTag = getOneTagByName(tagName, username);

    // 标签已经存在
    if (isTag != null ) {
        return isTag;
    }

    Tag tag = new Tag();
    tag.setName(tagName);
    tag.setUsername(username);
    tag.setId(idWorker.nextId());
    tag.setCreatedTime(new Date());
    tag.setModifiedTime(new Date());

    tagMapper.insertOneTag(tag);

    logger.info(username + " insert tag " + tag.getId() + " successfully");
    return tag;
}
 
开发者ID:ziwenxie,项目名称:leafer,代码行数:24,代码来源:TagServiceImpl.java

示例9: delete

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Override
@CacheEvict(cacheNames = "employee", key = "#empID")
public void delete(int empID) {
    logger.info("Запрос к базе на удаление сотрудника с ID: " + empID);
    String hql =
            "update EmployeeHistory E set E.isActive = false, " +
                    "E.endDate = :currentTimestamp, E.isDeleted = true" +
                    " where (E.empID = :empID) and (E.isActive = :state)";
    Timestamp currentTime = Timestamp.valueOf(LocalDateTime.now());
    Session session = getSession();
    try{
        session.createQuery(hql)
                .setTimestamp("currentTimestamp", currentTime)
                .setInteger("empID", empID)
                .setBoolean("state", true)
                .executeUpdate();
    }catch (HibernateException e){
        logger.error(e.getStackTrace());
        throw new MyRuntimeException(StuffExceptions.DATABASE_ERROR);
    }
}
 
开发者ID:Witerium,项目名称:stuffEngine,代码行数:22,代码来源:HibernateEmployeeDao.java

示例10: updateEmployee

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Override
@CacheEvict(cacheNames = "employee", key = "#employee.empID", beforeInvocation = true)
public Employee updateEmployee(Employee employee) {
    EmployeeHistory employeeHistory = new EmployeeHistory(employee);
    logger.info("Запрос к базе на изменение сотрудника с ID: " + employee.getEmpID());
    Timestamp currentTime = Timestamp.valueOf(LocalDateTime.now());
    String hql = "update EmployeeHistory E set E.isActive = false, E.endDate = :currentTimestamp " +
            "where (E.empID = :empId) and (E.isActive = :state)";

    Session session = getSession();
    try {
        session.createQuery(hql)
                .setTimestamp("currentTimestamp", currentTime)
                .setInteger("empId", employee.getEmpID())
                .setBoolean("state", true).executeUpdate();
        employeeHistory.setStartDate(currentTime);
        session.save(employeeHistory);
    } catch (HibernateException e){
        logger.error(e.getStackTrace());
        throw new MyRuntimeException(StuffExceptions.DATABASE_ERROR);
    }
    return read(employee.getEmpID());
}
 
开发者ID:Witerium,项目名称:stuffEngine,代码行数:24,代码来源:HibernateEmployeeDao.java

示例11: deletePost

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Caching(evict = {
    @CacheEvict(value = CACHE_POST, key = "#post.id.toString()"),
    @CacheEvict(value = CACHE_COUNT_USER_TAG_POSTS, key = "#post.user.id.toString().concat('_tags_posts_count')", allEntries = true),
    @CacheEvict(value = TagService.CACHE_COUNT_USER, key = "#post.user.id.toString().concat('_posts_count')")
})
@Transactional
public void deletePost(Post post) {
    PostStatus status = post.getStatus();
    postRepository.delete(post.getId());

    if (status == PostStatus.PUBLIC) {
        Set<Tag> tags = tagRepository.findPostTags(post.getId());
        hotPostService.removeHotPost(post);
        hotPostService.removeTaggedPost(post, tags);
        newPostsService.remove(post.getId());
        newPostsService.removeTaggedPost(post.getId(), tags);
        countingService.decPublicPostsCount();
        tags.forEach(tagService::decreasePostCountByOne); // 标签文章统计需要减一
    }

    PostSearchService.deleteIndex(post.getId());
    countingService.decPostsCount();
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:24,代码来源:PostService.java

示例12: followTag

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Transactional
@CacheEvict(value=CACHE_COUNT_USER, key="#userId.toString().concat('_followed_tags_count')")
public synchronized Long followTag(Long userId, Tag tag) {
    User user = userRepository.findOne(userId);

    if (user.getFollowingTags().contains(tag))
        return tag.getFollowersCount();

    user.getFollowingTags().add(tag);
    userRepository.save(user);

    tag.setFollowersCount(tag.getFollowersCount() + 1);
    tagRepository.save(tag);

    return tag.getFollowersCount();
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:17,代码来源:TagService.java

示例13: unFollowTag

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Transactional
@CacheEvict(value=CACHE_COUNT_USER, key="#userId.toString().concat('_followed_tags_count')")
public synchronized Long unFollowTag(Long userId, Tag tag) {
    User user = userRepository.findOne(userId);

    if (!user.getFollowingTags().contains(tag))
        return tag.getFollowersCount();

    user.getFollowingTags().remove(tag);
    userRepository.save(user);

    tag.setFollowersCount(tag.getFollowersCount() - 1);
    tagRepository.save(tag);

    return tag.getFollowersCount();
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:17,代码来源:TagService.java

示例14: delete

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Override
@Caching(
		evict = {
				@CacheEvict(key="#object.id"),
				@CacheEvict(cacheResolver="secondaryCacheResolver", allEntries=true)
			}
		)
public T delete(T object) throws DataAccessException {
	if (logger.isDebugEnabled())
		logger.debug("type {} delete", type);
	try {
		mongoOperations.remove(object);
		return object;
	} catch (Exception e) {
		throw new DataAccessException(e);
	}

}
 
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:19,代码来源:GenericDaoImpl.java

示例15: deleteRelatePermissionResource

import org.springframework.cache.annotation.CacheEvict; //导入依赖的package包/类
@Override
@CacheEvict( value = GlobalCacheConstant.USER_DETAILS_SERVICE_NAMESPACE, allEntries = true, condition = "#result != null" )
public boolean deleteRelatePermissionResource ( List< PermissionResourceVO > vos ) {
	final List< Long > resourceIds = vos.parallelStream()
										.map( PermissionResourceVO::getId )
										.collect( Collectors.toList() );
	// 删除资源
	AssertUtils.isTrue( ! super.deleteBatchIds( resourceIds ) , "资源删除失败" );

	// 删除相关角色资源中间表信息
	final List< Long > middleIds = rolePermissionResourceService.selectObjs(
		new Condition()
			.in( "permission_resource_id" , resourceIds )
			.setSqlSelect( "id" )
	);
	if ( CollectionUtils.isNotEmpty( middleIds ) ) {
		AssertUtils.isTrue( ! rolePermissionResourceService.deleteBatchIds( middleIds ) , "资源删除失败" );
	}
	return true;
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:21,代码来源:PermissionResourceServiceImpl.java


注:本文中的org.springframework.cache.annotation.CacheEvict类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。