Java Code Examples for org.springframework.cache.annotation.Cacheable
The following examples show how to use
org.springframework.cache.annotation.Cacheable.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: greenbot Author: vinay-lodha File: AwsInstanceImageService.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("CodeBlock2Expr") @Override @Cacheable("AwsInstanceImageService") public boolean isGreaterThanThreshold(int threshold, Tag includedTag, Tag excludedTag) { List<Image> images = regionService.regions() .stream() .map(region -> Ec2Client.builder().region(region).build()) .map(client -> query(includedTag, client)) .flatMap(Collection::stream) .filter(image -> { if (excludedTag == null) return true; return image.tags().stream() .noneMatch(tag -> tag.key().contentEquals(excludedTag.getKey()) && tag.value().contentEquals(excludedTag.getValue())); }) .limit(threshold + 1) .collect(Collectors.toList()); return images.size() > threshold; }
Example #2
Source Project: sk-admin Author: DengSinkiang File: MenuServiceImpl.java License: Apache License 2.0 | 6 votes |
@Override @Cacheable(key = "'tree'") public Object getMenuTree(List<Menu> menus) { List<Map<String, Object>> list = new LinkedList<>(); menus.forEach(menu -> { if (menu != null) { List<Menu> menuList = menuDao.findByPid(menu.getId()); Map<String, Object> map = new HashMap<>(16); map.put("id", menu.getId()); map.put("label", menu.getName()); if (menuList != null && menuList.size() != 0) { map.put("children", getMenuTree(menuList)); } list.add(map); } } ); return list; }
Example #3
Source Project: spring-microservice-exam Author: wells2333 File: AttachmentService.java License: MIT License | 6 votes |
/** * 获取附件的预览地址 * * @param attachment attachment * @return String * @author tangyi * @date 2019/06/21 17:45 */ @Cacheable(value = "attachment_preview#" + CommonConstant.CACHE_EXPIRE, key = "#attachment.id") public String getPreviewUrl(Attachment attachment) { attachment = this.get(attachment); if (attachment != null) { String preview = attachment.getPreviewUrl(); if (StringUtils.isNotBlank(preview) && !preview.startsWith("http")) { preview = "http://" + preview; } else { preview = AttachmentConstant.ATTACHMENT_PREVIEW_URL + attachment.getId(); } log.debug("GetPreviewUrl id: {}, preview url: {}", attachment.getId(), preview); return preview; } return ""; }
Example #4
Source Project: yshopmall Author: guchengwuyue File: MenuServiceImpl.java License: Apache License 2.0 | 6 votes |
/** * 获取菜单树 * * @param menus / * @return / */ @Override @Cacheable(key = "'tree'") public Object getMenuTree(List<Menu> menus) { List<Map<String,Object>> list = new LinkedList<>(); menus.forEach(menu -> { if (menu!=null){ List<Menu> menuList = menuMapper.findByPid(menu.getId()); Map<String,Object> map = new HashMap<>(16); map.put("id",menu.getId()); map.put("label",menu.getName()); if(menuList!=null && menuList.size()!=0){ map.put("children",getMenuTree(menuList)); } list.add(map); } } ); return list; }
Example #5
Source Project: web-flash Author: enilu File: FileService.java License: MIT License | 5 votes |
@Override @Cacheable(value = Cache.APPLICATION, key = "'" + CacheKey.FILE_INFO + "'+#id") public FileInfo get(Long id){ FileInfo fileInfo = fileInfoRepository.getOne(id); fileInfo.setAblatePath(configCache.get(ConfigKeyEnum.SYSTEM_FILE_UPLOAD_PATH) + File.separator+fileInfo.getRealFileName()); return fileInfo; }
Example #6
Source Project: greenbot Author: vinay-lodha File: ProdRegionService.java License: Apache License 2.0 | 5 votes |
@Override @Cacheable("ProdRegionService") public List<Region> regions() { Ec2Client client = Ec2Client.builder().build(); DescribeRegionsRequest request = DescribeRegionsRequest.builder().allRegions(true).build(); DescribeRegionsResponse response = client.describeRegions(request); return response.regions() .stream() .filter(re -> !"not-opted-in".equalsIgnoreCase(re.optInStatus())) .map(re -> Region.of(re.regionName())) .collect(toList()); }
Example #7
Source Project: sk-admin Author: DengSinkiang File: QuartzJobServiceImpl.java License: Apache License 2.0 | 5 votes |
@Override @Cacheable(key = "#p0") public QuartzJob findById(Long id) { QuartzJob quartzJob = quartzJobDao.findById(id).orElseGet(QuartzJob::new); ValidationUtil.isNull(quartzJob.getId(), "QuartzJob", "id", id); return quartzJob; }
Example #8
Source Project: sk-admin Author: DengSinkiang File: MenuServiceImpl.java License: Apache License 2.0 | 5 votes |
@Override @Cacheable(key = "#p0") public MenuDTO findById(long id) { Menu menu = menuDao.findById(id).orElseGet(Menu::new); ValidationUtil.isNull(menu.getId(), "Menu", "id", id); return menuMapper.toDto(menu); }
Example #9
Source Project: sk-admin Author: DengSinkiang File: JobServiceImpl.java License: Apache License 2.0 | 5 votes |
@Override @Cacheable(key = "#p0") public JobDTO findById(Long id) { Job job = jobRepository.findById(id).orElseGet(Job::new); ValidationUtil.isNull(job.getId(),"Job","id",id); return jobMapper.toDto(job); }
Example #10
Source Project: spring-boot-demo Author: jiangsongHB File: UserServiceImpl.java License: MIT License | 5 votes |
/** * 获取用户 * * @param id key值 * @return 返回结果 */ @Cacheable(value = "user", key = "#id") @Override public User get(Long id) { // 我们假设从数据库读取 log.info("查询用户【id】= {}", id); return DATABASES.get(id); }
Example #11
Source Project: MeetingFilm Author: daydreamdev File: ConstantFactory.java License: Apache License 2.0 | 5 votes |
/** * 通过角色id获取角色名称 */ @Override @Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId") public String getSingleRoleName(Integer roleId) { if (0 == roleId) { return "--"; } Role roleObj = roleMapper.selectById(roleId); if (ToolUtil.isNotEmpty(roleObj) && ToolUtil.isNotEmpty(roleObj.getName())) { return roleObj.getName(); } return ""; }
Example #12
Source Project: Continuous-Delivery-with-Docker-and-Jenkins-Second-Edition Author: PacktPublishing File: Calculator.java License: MIT License | 5 votes |
@Cacheable("sum") public int sum(int a, int b) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } return a + b; }
Example #13
Source Project: jeecg-boot-with-activiti Author: smallyunet File: JeecgDemoServiceImpl.java License: MIT License | 5 votes |
/** * 缓存注解测试: redis */ @Override @Cacheable(cacheNames = CacheConstant.TEST_DEMO_CACHE, key = "#id") public JeecgDemo getByIdCacheable(String id) { JeecgDemo t = jeecgDemoMapper.selectById(id); System.err.println("---未读缓存,读取数据库---"); System.err.println(t); return t; }
Example #14
Source Project: spring-analysis-note Author: Vip-Augus File: AnnotatedClassCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", sync = true) public Object throwCheckedSync(Object arg1) throws Exception { throw new IOException(arg1.toString()); }
Example #15
Source Project: spring-analysis-note Author: Vip-Augus File: DefaultCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", sync = true) public Long throwCheckedSync(Object arg1) throws Exception { throw new IOException(arg1.toString()); }
Example #16
Source Project: spring-analysis-note Author: Vip-Augus File: DefaultCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager") public Long customCacheManager(Object arg1) { return counter.getAndIncrement(); }
Example #17
Source Project: sophia_scaffolding Author: SophiaLeo File: UserServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override @Cacheable(value = GlobalsConstants.REDIS_USER_CACHE, unless = "#result == null", key = "T(com.scaffolding.sophia.common.base.constants.GlobalsConstants).USER_KEY_PREFIX.concat(T(String).valueOf(#userId))") public UserVo loadUserByUserId(String userId) { return new UserVo().buildVo(baseMapper.selectById(userId)); }
Example #18
Source Project: java-technology-stack Author: codeEngraver File: CacheResolverCustomizationTests.java License: MIT License | 4 votes |
@Cacheable(cacheResolver = "namedCacheResolver") public Object getWithNamedCacheResolution(Object key) { return this.counter.getAndIncrement(); }
Example #19
Source Project: spring-analysis-note Author: Vip-Augus File: AnnotatedClassCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", sync = true) public Object cacheSyncNull(Object arg1) { return null; }
Example #20
Source Project: java-technology-stack Author: codeEngraver File: DefaultCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName") public Long unknownCustomKeyGenerator(Object arg1) { return this.counter.getAndIncrement(); }
Example #21
Source Project: spring-analysis-note Author: Vip-Augus File: AnnotatedClassCacheableService.java License: MIT License | 4 votes |
@Override @Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#a0 == 3") }, evict = { @CacheEvict("secondary") }) public Object multiConditionalCacheAndEvict(Object arg1) { return this.counter.getAndIncrement(); }
Example #22
Source Project: spring-analysis-note Author: Vip-Augus File: AnnotatedClassCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable("testCache") public Object varArgsKey(Object... args) { return this.counter.getAndIncrement(); }
Example #23
Source Project: sk-admin Author: DengSinkiang File: MenuServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override @Cacheable public List<MenuDTO> queryAll(MenuQuery criteria) { // Sort sort = new Sort(Sort.Direction.DESC,"id"); return menuMapper.toDto(menuDao.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); }
Example #24
Source Project: sk-admin Author: DengSinkiang File: MenuServiceImpl.java License: Apache License 2.0 | 4 votes |
@Override @Cacheable(key = "'pid:'+#p0") public List<Menu> findByPid(long pid) { return menuDao.findByPid(pid); }
Example #25
Source Project: java-technology-stack Author: codeEngraver File: CacheSyncFailureTests.java License: MIT License | 4 votes |
@Cacheable(cacheNames = "testCache", sync = true) @CacheEvict(cacheNames = "anotherTestCache", key = "#arg1") public Object syncWithAnotherOperation(Object arg1) { return this.counter.getAndIncrement(); }
Example #26
Source Project: java-technology-stack Author: codeEngraver File: CacheReproTests.java License: MIT License | 4 votes |
@Cacheable("itemCache") public Optional<TestBean> findById(String id) { return Optional.of(new TestBean(id)); }
Example #27
Source Project: java-technology-stack Author: codeEngraver File: DefaultCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName") public Long unknownCustomCacheManager(Object arg1) { return counter.getAndIncrement(); }
Example #28
Source Project: java-technology-stack Author: codeEngraver File: CacheReproTests.java License: MIT License | 4 votes |
@Cacheable(value = "itemCache", sync = true) public Optional<TestBean> findById(String id) { return Optional.of(new TestBean(id)); }
Example #29
Source Project: stone Author: Alension File: GalleryServiceImpl.java License: GNU General Public License v3.0 | 4 votes |
/** * 查询所有图片 不分页 * * @return List */ @Override @Cacheable(value = GALLERIES_CACHE_NAME, key = "'gallery'") public List<Gallery> findAll() { return galleryRepository.findAll(); }
Example #30
Source Project: java-technology-stack Author: codeEngraver File: AnnotatedClassCacheableService.java License: MIT License | 4 votes |
@Override @Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName") public Object unknownCustomCacheManager(Object arg1) { return counter.getAndIncrement(); }