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


Java Cacheable類代碼示例

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


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

示例1: getDownloadedSizeByUserSince

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
/**
 * Returns the cumulative downloaded size by a user on a given period.
 *
 * @param user   associate user to downloads.
 * @param period period time in millisecond.
 * @return cumulative downloaded size.
 */
@Transactional (readOnly = true)
@Cacheable (value = "network_download_size", key = "#user.getUUID ()", condition = "#user != null")
public Long getDownloadedSizeByUserSince (final User user, final Long period)
{
   Objects.requireNonNull (user, "'user' parameter is null");
   Objects.requireNonNull (period, "'period' parameter is null");

   long current_timestamp = System.currentTimeMillis ();
   if (period < 0 || period > current_timestamp)
   {
      throw new IllegalArgumentException ("period time too high");
   }
   Date date = new Date (current_timestamp - period);

   return networkUsageDao.getDownloadedSizeByUserSince (user, date);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:24,代碼來源:NetworkUsageService.java

示例2: getAllDic

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Cacheable(value = Constants.CACHE_NAMESPACE + "sysDics")
public Map<String, Map<String, String>> getAllDic() {
	Map<String, Object> params = InstanceUtil.newHashMap();
	params.put("orderBy", "type_,sort_no");
	List<SysDic> list = queryList(params);
	Map<String, Map<String, String>> resultMap = InstanceUtil.newHashMap();
	for (SysDic sysDic : list) {
		if (sysDic != null) {
			String key = sysDic.getType();
			if (resultMap.get(key) == null) {
				Map<String, String> dicMap = InstanceUtil.newHashMap();
				resultMap.put(key, dicMap);
			}
			if (StringUtils.isNotBlank(sysDic.getParentCode())) {
				resultMap.get(key).put(sysDic.getParentCode() + sysDic.getCode(), sysDic.getCodeText());
			} else {
				resultMap.get(key).put(sysDic.getCode(), sysDic.getCodeText());
			}
		}
	}
	return resultMap;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:23,代碼來源:SysDicService.java

示例3: getFinalVersionsGreaterEquals

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Override
@Cacheable(cacheNames = "gradleVersions", sync = true)
public List<GradleVersion> getFinalVersionsGreaterEquals(GradleVersion minVersion) {
    List<GradleVersion> allVersions = new ArrayList<>();
    JSONArray versions = new JSONArray(remoteGradleVersionResolver.getAllVersions());

    for (int i = 0; i < versions.length(); i++) {
        JSONObject version = versions.getJSONObject(i);

        if (isFinalVersion(version)) {
            GradleVersion semanticVersion = new GradleVersion(version.getString(VERSION_ATTRIBUTE));

            if (isGreaterEquals(minVersion, semanticVersion)) {
                allVersions.add(semanticVersion);
            }
        }
    }

    return allVersions;
}
 
開發者ID:bmuschko,項目名稱:gradle-initializr,代碼行數:21,代碼來源:JsonGradleVersionReader.java

示例4: countDownloadsByUserSince

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
/**
 * Returns number of downloads by a user on a given period.
 *
 * @param user   associate user to downloads.
 * @param period period time in millisecond.
 * @return number of downloads.
 */
@Transactional (readOnly = true)
@Cacheable (value = "network_download_count", key = "#user.getUUID ()", condition = "#user != null")
public int countDownloadsByUserSince (final User user, final Long period)
{
   Objects.requireNonNull (user, "'user' parameter is null");
   Objects.requireNonNull (period, "'period' parameter is null");

   long current_timestamp = System.currentTimeMillis ();
   if (period < 0 || period > current_timestamp)
   {
      throw new IllegalArgumentException ("period time too high");
   }
   Date date = new Date (current_timestamp - period);
   return networkUsageDao.countDownloadByUserSince (user, date);
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:23,代碼來源:NetworkUsageService.java

示例5: download

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
/**
 * Download secrets cli binary. For better performance, the file resource
 * is cached in memory (for 5 min, default cache timeout)  if it's less
 * than 10 MB.
 *
 * @return file resource.
 * @throws IOException throws if any error reading the file.
 */
@GetMapping("/download")
@Cacheable("secrets-cli")
@ApiOperation(value = "Download Secrets CLI latest version.")
public ResponseEntity<Resource> download() throws IOException {
    File file = cliPath.toFile();
    if (file.exists() && file.isFile() && file.length() < 10_000_000) {
        log.info("Downloading the secrets cli.");
        ByteArrayResource bar = new ByteArrayResource(Files.readAllBytes(cliPath));
        return ResponseEntity.ok()
                .header("Content-disposition", "attachment;filename=" + file.getName())
                .contentLength(file.length())
                .contentType(MediaType.parseMediaType("application/octet-stream"))
                .body(bar);

    } else {
        log.error(format("Invalid secrets cli binary %s. Size: %d bytes.", cliPath, file.length()));
        throw new KeywhizException(INTERNAL_SERVER_ERROR.value(), "Latest secret cli binary is not available on server.");
    }
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:28,代碼來源:CliController.java

示例6: getName

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Cacheable(value = Constants.CACHE_NAMESPACE + "sysParamName")
public String getName(String key) {
	if (StringUtils.isBlank(key)) {
		return "";
	}
	Map<String, Object> params = InstanceUtil.newHashMap();
	params.put("orderBy", "type_,sort_no");
	List<SysParam> list = queryList(params);
	for (SysParam sysParam : list) {
		if (sysParam != null) {
			if (key.equals(sysParam.getParamKey())) {
				return sysParam.getRemark();
			}
		}
	}
	return "";
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:18,代碼來源:SysParamService.java

示例7: getAllSubDepts

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Override
@Cacheable(cacheNames = "subdepts", key = "#depId")
public List<Department> getAllSubDepts(Integer depId) {
    logger.info("Запрос к базе на чтение подразделений отдела с ID: " + depId);
    List<Department> departments;
    Session session = getSession();
    try{
        String sqlQueryForSubDepts1 = "SELECT DEPT_ID, PARENT_DEPT_ID, DEPT_NAME, DEPT_HEAD_ID FROM DEPARTMENT START WITH PARENT_DEPT_ID = :deptId CONNECT BY  PRIOR  DEPT_ID = PARENT_DEPT_ID";
        departments = session.createSQLQuery(sqlQueryForSubDepts1)
                .addEntity(Department.class)
                .setParameter("deptId", depId)
                .list();
    }catch (HibernateException e){
        logger.error(e.getStackTrace());
        throw new MyRuntimeException(StuffExceptions.DATABASE_ERROR);
    }

    return departments;
}
 
開發者ID:Witerium,項目名稱:stuffEngine,代碼行數:20,代碼來源:HibernateDepartmentDao.java

示例8: getUserByName

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
/**
 * Return user corresponding to given user name.
 * 
 * @param name User name.
 * @throws RootNotModifiableException
 */
@PreAuthorize ("hasAnyRole('ROLE_USER_MANAGER','ROLE_DATA_MANAGER','ROLE_SYSTEM_MANAGER')")
@Transactional (readOnly=true, propagation=Propagation.REQUIRED)
@Cacheable (value = "userByName", key = "#name?.toLowerCase()")
public User getUserByName (String name) throws RootNotModifiableException
{
   User u = this.getUserNoCheck (name);
   checkRoot (u);
   return u;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:16,代碼來源:UserService.java

示例9: countUserPostsByTags

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Cacheable(value = CACHE_COUNT_USER_TAG_POSTS, key = "#userId.toString().concat('_tags_posts_count')")
public List<PostTagCountDTO> countUserPostsByTags(Long userId) {
    List<Object[]> counts = postRepository.countUserPostsByTags(userId);
    List<PostTagCountDTO> result = new ArrayList<>();
    counts.forEach(count -> result.add(new PostTagCountDTO((Long) count[0], (Tag) count[1])));
    return result;
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:8,代碼來源:PostService.java

示例10: getBinaryResource

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
/**
 * Return the binary content of the resource at the specified location.
 * @param location a resource location
 * @return the content of the resource
 */
@Cacheable("project-resources")
public byte[] getBinaryResource(String location) {
	try (InputStream stream = getInputStream(location)) {
		return StreamUtils.copyToByteArray(stream);
	}
	catch (IOException ex) {
		throw new IllegalStateException("Cannot get resource", ex);
	}
}
 
開發者ID:rvillars,項目名稱:edoras-one-initializr,代碼行數:15,代碼來源:ProjectResourceLocator.java

示例11: getContactDetails

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Cacheable(value = CONTACT_DETAILS_CACHE_NAME, key = "#person.personalCode")
public UserPreferences getContactDetails(Person person) {
  String url = episServiceUrl + "/contact-details";

  log.info("Getting contact details from {} for {} {}",
      url, person.getFirstName(), person.getLastName());

  ResponseEntity<UserPreferences> response = restTemplate.exchange(
      url, HttpMethod.GET, new HttpEntity(getHeaders()), UserPreferences.class);

  return response.getBody();
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:13,代碼來源:EpisService.java

示例12: getById

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Override
@Cacheable(key="#id" ,unless="#result == null")
public T getById(Object id) throws DataAccessException {
	if (logger.isDebugEnabled())
		logger.debug("type {} getById", type);
	try{
		return mongoOperations.findById(id, type);
	}catch(Exception e){
		throw new DataAccessException(e);
	}
}
 
開發者ID:satyendranit,項目名稱:pokemon,代碼行數:12,代碼來源:GenericDaoImpl.java

示例13: saveMessage

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Override
@Cacheable( value = "message")
public boolean saveMessage(Message message) throws WebQQServiceException {
    if(Objects.isNull(message.getSendUser())){
       message.setSendUser(new User(SecurityContextUtils.getCurrentUser()));
    }
    return doSaveMessage(message);
}
 
開發者ID:damingerdai,項目名稱:web-qq,代碼行數:9,代碼來源:MessageServiceImpl.java

示例14: queryDicByType

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
@Cacheable(value = Constants.CACHE_NAMESPACE + "sysDics")
public Map<String, String> queryDicByType(String key) {
	Map<String, String> resultMap = applicationContext.getBean(SysDicService.class).getAllDic().get(key);
	if (resultMap == null) {
		return InstanceUtil.newHashMap();
	}
	return resultMap;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:9,代碼來源:SysDicService.java

示例15: getPerson

import org.springframework.cache.annotation.Cacheable; //導入依賴的package包/類
/**
 * 自動生成key
 * 
 * @param id
 * @return
 */
@Cacheable(value = "userCache", keyGenerator = "wiselyKeyGenerator")
public Person getPerson(String id) {
	log.info("[userCacheManager]沒有緩存,則執行下麵內容。");
	Person person = new Person();
	person.setAge(10);
	person.setGender("男");
	person.setName(id);
	person.setId(id);
	return person;
}
 
開發者ID:Fourwenwen,項目名稱:consistent-hashing-redis,代碼行數:17,代碼來源:PersonService.java


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