沫言|java:shiro高级篇——1( 二 )
packagecom.itheima.shiro.core;importorg.apache.shiro.cache.Cache;importorg.apache.shiro.cache.CacheException;/***@Description简单的缓存管理接口*/publicinterfaceSimpleCacheService{/***功能说明::新增缓存堆到管理器*/voidcreateCache(StringcacheName,Cachecache)throwsCacheException;/***方法名::getCache*功能说明::获取缓存堆*/CachegetCache(StringcacheName)throwsCacheException;/***方法名::removeCache*功能说明::移除缓存堆*/voidremoveCache(StringcacheName)throwsCacheException;/***方法名::updateCahce*功能说明::更新缓存堆*/voidupdateCahce(StringcacheName,Cachecache)throwsCacheException;}SimpleCacheServiceImpl
【沫言|java:shiro高级篇——1】调用RedissonClient去实现缓存 , 同时使用ShiroRedissionSerialize实现序列化
packagecom.itheima.shiro.core.impl;importcom.itheima.shiro.constant.CacheConstant;importcom.itheima.shiro.core.SimpleCacheService;importcom.itheima.shiro.utils.ShiroRedissionSerialize;importlombok.extern.log4j.Log4j2;importorg.apache.shiro.SecurityUtils;importorg.apache.shiro.cache.Cache;importorg.apache.shiro.cache.CacheException;importorg.redisson.api.RBucket;importorg.redisson.api.RedissonClient;importorg.springframework.stereotype.Component;importjavax.annotation.Resource;importjava.util.concurrent.TimeUnit;/****@Description简单的缓存管理接口的实现*/@Log4j2@ComponentpublicclassSimpleCacheServiceImplimplementsSimpleCacheService{@Resource(name="redissonClientForShiro")RedissonClientredissonClient;@OverridepublicvoidcreateCache(Stringname,Cachecache){RBucketbucket=redissonClient.getBucket(CacheConstant.GROUP_CAS+name);bucket.trySet(ShiroRedissionSerialize.serialize(cache),SecurityUtils.getSubject().getSession().getTimeout()/1000,TimeUnit.SECONDS);}@SuppressWarnings("unchecked")@OverridepublicCachegetCache(Stringname)throwsCacheException{RBucketbucket=redissonClient.getBucket(CacheConstant.GROUP_CAS+name);return(Cache)ShiroRedissionSerialize.deserialize(bucket.get());}@OverridepublicvoidremoveCache(Stringname)throwsCacheException{RBucketbucket=redissonClient.getBucket(CacheConstant.GROUP_CAS+name);bucket.delete();}@OverridepublicvoidupdateCahce(Stringname,Cachecache){RBucketbucket=redissonClient.getBucket(CacheConstant.GROUP_CAS+name);bucket.set(ShiroRedissionSerialize.serialize(cache),SecurityUtils.getSubject().getSession().getTimeout()/1000,TimeUnit.MILLISECONDS);}}
- Java|计算机专业的本科生,该选择学习Java技术体系还是.NET技术体系
- 小熊回收站|-链表阻塞队列和数组阻塞队列的异同,Java并发编程
- Java|马化腾登顶中国首富,微信、QQ却都免费使用,腾讯到底咋赚钱的?
- Java|为什么美团骑手总是闯红灯昵
- 沫言|小米100wTypeC扩展坞来了,买苹果本都少不了转接口
- 阿里巴巴|java三大集合遍历方法
- 编程|JAVA基础-网络编程
- 沫言|告别重复劳动,网易后端教你这样做,十小时代码量一小时搞定
- Java|Java中的天使和魔鬼:Unsafe类
- 沫言|预算4K选谁更省心?,国产“三剑客”受学生党追捧