當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。