手动使用cache
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//ehcache缓存使用
Element el = null;
CacheManager manager = CacheManager.create();
Cache cache = manager.getCache("myCache");
if(cache.isKeyInCache("shiro"+principals)){
el = cache.get("shiro"+principals);
return (AuthorizationInfo) el.getObjectValue();
}
//ehcache缓存使用
String userName = (String) principals.getPrimaryPrincipal();
Front_login login= new Front_login();
login.setAccount(userName);
int id=fi.select_loginlk(login).getId();
login.setId(id);
Front_login returnLogin = fi.get_login(login);
//角色集合
Set<String> Roles = new HashSet<String>();
for(Front_role r :returnLogin.getRoles()){
Roles.add(r.getName());
}
System.out.println("调用shiro自定义域");
//权限集合
Set<String> Urls = fi.get_all_url(login);
SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();
authorizationInfo.addRoles(Roles);
authorizationInfo.addStringPermissions(Urls);
//ehcache缓存使用
if(authorizationInfo!=null){
el = new Element("shiro"+principals, authorizationInfo);
cache.put(el);
}
//ehcache缓存使用
return authorizationInfo;
}
分享到:
相关推荐
这里面说的“相同参数”一定要正确理解,也就是说同一个方法使用了@Cacheable注解,但是有不同的参数组合来调用这个方法,则会才产生你的组合数个key来存储缓存数据! 好了,接下来我们看一下,这注解的每个参数...
关于@Cacheable注解在方法上根据请求参数拉起缓存内容,同时@CacheEvict 注解在方法上清空指定key缓存的原理内容
主要介绍了详解Spring缓存注解@Cacheable,@CachePut , @CacheEvict使用,非常具有实用价值,需要的朋友可以参考下
spring + redis使用@Cacheable,@CachePut,@CacheEvict详细步骤
只要发生删改查,就把集合类缓存销毁对于查询方法:@Cacheable(value=“obj”) 或 @Cacheable(value=“objList”)对于修
@Cacheable:查找缓存——>有就返回——>没有就执行方法体——>将结果缓存起来 @CachePut:执行方法体——>将结果缓存起来。 根据不同返回结果执行不同逻辑 如果返回结果为null,当我们再次进行该key值的查询的...
本篇文章主要介绍了spring整合redis缓存并以注解(@Cacheable、@CachePut、@CacheEvict)形式使用,具有一定的参考价值,有兴趣的可以了解一下。
例如,使用@Cacheable注解来指定一个方法的结果应该被缓存。 @Cacheable:将方法的结果缓存起来,下次调用该方法时,如果传入的参数相同,则直接返回缓存中的数据。 @CacheEvict:清除指定方法的缓存数据,可以配置...
此注解表明在进入方法之前,Spring 会先去缓存服务器中査找对应 key 的缓存值,如果找到缓存值,那么 Spring 将不会再调用方法,而是将缓存值读出,返回给调用者;如果没有找到缓存值,那么 Spring 就会执行你的...
ehcache :添加依赖 pom.xml 2、添加配置文件ehcache.xml 3、添加注解@EnableCaching @Cacheable 4、插入缓存 5 读取缓存 6 设置缓存过期时间ehcache.xml -->timeToLiveSeconds。 redis : 1、添加依赖 pom.xml 2、...
本文将详细介绍Spring Boot中最常用的注解,包括@SpringBootApplication、@Component、@Service、@Repository、@Controller、@RequestMapping、@GetMapping、@PostMapping、@PutMapping、@DeleteMapping、@Autowired...
和cacheable中的key类似,和value组合生成缓存 allEntries 参数 allEntries 意思是:是否删除整个缓存(value中指定的值),默认是false 当为true时,会把所有value对应的缓存全部删除 当为false时,此时只会删除...
TypeScript存储模块(内存,sessionStorage,localStorage)和@Cacheable装饰器 安装 npm install rebirth-storage --save 如何使用? 用于存储数据的StorageService 注册StorageService import { ...
echache缓存注解说明------ Spring为我们提供了几个注解来支持Spring Cache。其核心主要是@Cacheable和@CacheEvict。使用@Cacheable标记的方法在执行后Spring Cache将缓存其返回结果,而使用@CacheEvict标记的方法...
3. Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用 3 3.1. @Cacheable 4 3.2. @CachePut 6 3.3. @CacheEvict 7 3.4. @Caching 8 3.5. 使用自定义注解 8 4. 使用Lettuce 操作redis单机版和redis集群 9
前言 java动态代理主要有2种,Jdk动态代理、Cglib动态代理,本文主要讲解Jdk动态代理的使用、运行机制、以及源码分析。当spring没有手动开启Cglib动态代理,即:或@EnableAspectJAutoProxy...当@Cacheable注解在方
通过spring-cache对方法进行缓存,同时验证如何通过key更新指定的缓存!
在Spring体系中使用redis.zip spring集成redis缓存
注解介绍等详细说明及使用: • @Controller • @Service • @Autowired • @RequestMapping • @RequestParam • @ModelAttribute • @Cacheable • @CacheFlush • @Resource • @PostConstruct • @...
缓存是实际工作中非经常常使用的一种提高性能的方法, 我们会在很多场景下来使用缓存。下面这篇文章主要给大家介绍了关于Spring Cache的基本使用与实现原理的相关资料,文中通过示例代码介绍的非常详细,需要的朋友...