Jboot集成Redis来实现缓存技术方案


声明:本文转载自https://my.oschina.net/yangfuhai/blog/1057857,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

现在osc上有大量的文章来说springboot整合redis实现缓存的技术方案,比如:《SpringBoot集成Redis来实现缓存技术方案》,网址:https://my.oschina.net/feinik/blog/1023601

但是殊不知如果使用Jboot来实现使用redis的技术方案,要比springboot简单100000000000倍。

第一步:maven依赖jboot

<dependency>     <groupId>io.jboot</groupId>     <artifactId>jboot</artifactId>     <version>1.0-alpha4.1</version> </dependency>

第二步:配置jboot的缓存配置文件jboot.properties

jboot.cache.type= redis jboot.cache.redis.host = 127.0.0.1

第三步:在Service使用缓存(注解方式)

@Singleton public class UserServiceImpl implements UserService  {          @Cacheable(name = "user",key = "#(id)")         public User getUserById(@Named("id") String id) {             return new User();         }  }   @Singleton public class ArticleServiceImpl implements ArticleService  {          @Cacheable(name = "article", key = "articleListCache:#(user.id)",  unless="user == null")         public List<Article> getArticleListByUser(@Named("user") User byUser) {             //do your something             return new List<Article>();         }  }

第四步:使用(controller直接使用)

@RequestMapping("/user") public class UserController extends JbootController {      @Inject     UserService userService;      public void index() {         User user = userService.getById("123");         setAttr("user",user);         render("index.html");     }  } 

 

总结:

比springboot好用1000000000000倍。

本文发表于2017年06月28日 16:36
(c)注:本文转载自https://my.oschina.net/yangfuhai/blog/1057857,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2352 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1