服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - resty的缓存技术设计及使用

resty的缓存技术设计及使用

2022-09-01 10:44Dreampie Java教程

这篇文章主要为大家介绍了resty缓存技术的设计及使用示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步

resty的缓存设计极其简单,目前分为两部分,model数据缓存和session缓存,第3条使用权限控制时,session被存入缓存,便于实现分布式,支持 ehcache和 redis

1. 在application.properties里启用缓存,并配置缓存对象

?
1
2
3
app.cacheEnabled=true
#如果不配置cacheManager对象,默认使用ehcacheManager
#app.cacheManager=cn.dreampie.cache.redis.RedisManager

2. 在resources下配置缓存文件

ehcache.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<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

?
1
2
3
4
5
6
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的构造参数开启缓存

?
1
2
3
4
//model
@Table(name = "sec_user",generatedKey="id", primaryKey = "sid", cached = true)
//record
Record recordDAO = new Record("sec_user", true);

以上就是resty的缓存技术设计及使用的详细内容,更多关于resty缓存设计使用的资料请关注服务器之家其它相关文章!

原文链接:https://dreampie.gitbooks.io/resty-chs/content/cache.html

延伸 · 阅读

精彩推荐