文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
使用缓存技术
resty 的缓存设计极其简单,目前分为两部分,model 数据缓存和 session 缓存,第 3 条使用权限控制时,session 被存入缓存,便于实现分布式,支持 ehcache 和 redis
1. 在 application.properties 里启用缓存,并配置缓存对象
app.cacheEnabled=true
#如果不配置 cacheManager 对象,默认使用 ehcacheManager
#app.cacheManager=cn.dreampie.cache.redis.RedisManager
2. 在 resources 下配置缓存文件
ehcache.xml
<ehcache name="shiro" updateCheck="false" monitoring="autodetect"
dynamicConfig="true">
<diskStore path="java.io.tmpdir/resty-ehcache"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="360"
timeToLiveSeconds="360"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"/>
<cache name="_credential"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1200"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"/>
<!--session 缓存永久的 程序自动清理过期的数据-->
<cache name="_session"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"/>
</ehcache>
redis.properties
redis.host=127.0.0.1:6379
#如果使用 ShardInfo 逗号分割
#redis.shard.host=127.0.0.1:6379,127.0.0.1:6379
redis.timeout=0
redis.pool.maxWaitMillis=-1
redis.pool.minEvictableIdleTimeMillis=1800000
3. 在 Model 的 table 配置中,Record 的构造参数开启缓存
//model
@Table(name = "sec_user",generatedKey="id", primaryKey = "sid", cached = true)
//record
Record recordDAO = new Record("sec_user", true);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论