当前位置: 首页>>代码示例>>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;未经允许,请勿转载。