Guava-技术专题-Cache用法介绍

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"背景"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 缓存的主要"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"作用是暂时在内存中保存业务系统的数据处理结果"},{"type":"text","text":",并且等待"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"下次访问使用"},{"type":"text","text":"。在日长开发有很多场合,有一些数据量不是很大,不会经常改动,"},{"type":"text","marks":[{"type":"strong"}],"text":"并且访问非常频繁"},{"type":"text","text":"。但是由于受限于硬盘IO的性能或者远程网络等原因获取可能非常的费时。会导致我们的程序非常缓慢,这在某些业务上是不能忍的!而缓存正是解决这类问题的神器!"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/af/af97cfcf1a86ef587e70dd9a00064a2c.webp","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 当然也并不是说你用了缓存你的系统就一定会变快,建议在用之前看一下"},{"type":"link","attrs":{"href":"https://link.jianshu.com/?t=http://kb.cnblogs.com/page/138696/","title":null},"content":[{"type":"text","text":"使用缓存的9大误区(上)"}],"marks":[{"type":"underline"}]},{"type":"text","text":" "},{"type":"link","attrs":{"href":"https://link.jianshu.com/?t=http://kb.cnblogs.com/page/144396/","title":null},"content":[{"type":"text","text":"使用缓存的9大误区(下)"}],"marks":[{"type":"underline"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 缓存在很多系统和架构中都用广泛的应用,例如:"}]},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":1,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"CPU缓存"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":2,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"操作系统缓存"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":3,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"HTTP缓存"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":4,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"数据库缓存"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":5,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"静态文件缓存"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":6,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"本地缓存"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":7,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"分布式缓存"}]}]}]},{"type":"horizontalrule"},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 可以说在计算机和网络领域,缓存是无处不在的。可以这么说,只要有硬件性能不对等,涉及到网络传输的地方都会有缓存的身影。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 缓存总体可分为两种 "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"集中式缓存"},{"type":"text","text":" 和 "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"分布式缓存"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"“集中式缓存\"与\"分布式缓存\""},{"type":"text","text":"的区别其实就在于"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"“集中”与\"非集中\""},{"type":"text","text":"的概念,其对象可能是服务器、内存条、硬盘等。"}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"比如"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"1.服务器版本"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"缓存集中在一台服务器上,为集中式缓存。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"缓存分散在不同的服务器上,为分布式缓存。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"2.内存条版本"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"缓存集中在一台服务器的一条内存条上,为集中式缓存。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"缓存分散在一台服务器的不同内存条上,为分布式缓存。"}]}]}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"3.硬盘版本"}]},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"缓存集中在一台服务器的一个硬盘上,为集中式缓存。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"缓存分散在一台服务器的不同硬盘上,为分布式缓存。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 想了解分布式缓存可以看一下"},{"type":"link","attrs":{"href":"https://link.jianshu.com/?t=http://os.51cto.com/art/201306/397999.htm","title":null},"content":[{"type":"text","text":"浅谈分布式缓存那些事儿"}],"marks":[{"type":"underline"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 这是几个当前比较流行的java 分布式缓存框架"},{"type":"link","attrs":{"href":"https://link.jianshu.com/?t=http://developer.51cto.com/art/201411/457423.htm","title":null},"content":[{"type":"text","text":"5个强大的Java分布式缓存框架推荐"}],"marks":[{"type":"underline"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 集中式内存缓存guava cache,这是当前我们项目正在用的缓存工具,研究一下感觉还蛮好用的。当然也有很多其他工具,还是看个人喜欢。oschina上面也有很多类似开源的"},{"type":"link","attrs":{"href":"https://link.jianshu.com/?t=http://www.oschina.net/project/tag/132/cachesystem?sort=view&lang=19&os=0","title":null},"content":[{"type":"text","text":"java缓存框架"}],"marks":[{"type":"underline"}]}]},{"type":"heading","attrs":{"align":null,"level":1},"content":[{"type":"text","text":"正文"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Guava Cache"},{"type":"text","text":"与"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"ConcurrentMap"},{"type":"text","text":"很相似,但也不完全一样。最基本的区别是"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"ConcurrentMap"},{"type":"text","text":"会一直保存所有添加的元素,直到显式地移除。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 相对地,"},{"type":"text","marks":[{"type":"strong"}],"text":"Guava Cache"},{"type":"text","text":"为了限制内存占用,通常都设定为自动回收元素。在某些场景下,尽管"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"LoadingCache "},{"type":"text","text":"不回收元素,它也是很有用的,因为它会自动加载缓存。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"strong"}],"text":"Guava Cache"},{"type":"text","text":"是在内存中"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"缓存数据"},{"type":"text","text":",相比较于数据库或"},{"type":"text","marks":[{"type":"strong"}],"text":"redis"},{"type":"text","text":"存储,访问内存中的数据会更加高效。"},{"type":"text","marks":[{"type":"strong"}],"text":"Guava"},{"type":"text","text":"官网介绍,下面的这几种情况可以考虑使用"},{"type":"text","marks":[{"type":"strong"}],"text":"Guava Cache"},{"type":"text","text":":"}]},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":1,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"愿意消耗一些内存空间来提升速度。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":2,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"预料到某些键会被多次查询。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":3,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"缓存中存放的数据总量不会超出内存容量。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 所以,可以将程序频繁用到的少量数据存储到Guava Cache中,以改善程序性能。下面对Guava Cache的用法进行详细的介绍。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"构建缓存对象"}]},{"type":"paragraph","attrs":{"indent":1,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 接口Cache代表一块缓存,它有如下方法:"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public interface Cache {\n 2 V get(K key, Callable extends V> valueLoader) throws ExecutionException;\n 4 ImmutableMap getAllPresent(Iterable> keys);\n 6 void put(K key, V value);\n 8 void putAll(Map extends K, ? extends V> m);\n10 void invalidate(Object key);\n12 void invalidateAll(Iterable> keys);\n14 void invalidateAll();\n16 long size();\n18 CacheStats stats();\n20 ConcurrentMap asMap();\n22 void cleanUp();\n23 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 可以通过"},{"type":"text","marks":[{"type":"strong"}],"text":"CacheBuilder"},{"type":"text","text":"类构建一个缓存对象,"},{"type":"text","marks":[{"type":"strong"}],"text":"CacheBuilder"},{"type":"text","text":"类采用"},{"type":"text","marks":[{"type":"strong"}],"text":"builder"},{"type":"text","text":"设计模式,它的每个方法都返回"},{"type":"text","marks":[{"type":"strong"}],"text":"CacheBuilder"},{"type":"text","text":"本身,直到"},{"type":"text","marks":[{"type":"strong"}],"text":"build"},{"type":"text","text":"方法被调用。构建一个缓存对象代码如下。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"1 public class StudyGuavaCache {\n2 public static void main(String[] args) {\n3 Cache cache = CacheBuilder.newBuilder().build();\n4 cache.put(\"word\",\"Hello Guava Cache\");\n5 System.out.println(cache.getIfPresent(\"word\"));\n6 }\n7 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 上面的代码通过"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"CacheBuilder.newBuilder().build()"},{"type":"text","text":"这句代码创建了一个"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","text":"缓存对象,并在缓存对象中存储了key为word,value为Hello Guava Cache的一条记录。可以看到Cache非常类似于JDK中的Map,但是相比于Map,Guava Cache提供了很多更强大的功能。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 从"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"LoadingCache"},{"type":"text","text":"查询的正规方式是使用"},{"type":"codeinline","content":[{"type":"text","text":"get(K)"}]},{"type":"text","text":"方法。这个方法要么返回已经缓存的值,要么使用"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"CacheLoader"},{"type":"text","text":"向缓存原子地加载新值(通过"},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"load(String key)"}]},{"type":"text","text":" 方法加载)。由于CacheLoader可能抛出异常,"},{"type":"codeinline","content":[{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"LoadingCache.get(K)"}]},{"type":"text","text":"也声明抛出ExecutionException异常。如果你定义的CacheLoader没有声明任何检查型异常,则可以通过"},{"type":"codeinline","content":[{"type":"text","text":"getUnchecked(K)"}]},{"type":"text","text":"查找缓存;但必须注意,一旦CacheLoader声明了检查型异常,就不可以调用"},{"type":"codeinline","content":[{"type":"text","text":"getUnchecked(K)"}]},{"type":"text","text":"。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 LoadingCache cache = CacheBuilder.newBuilder()\n 2 .build(\n 3 new CacheLoader() {\n 4 public Value load(Key key) throws AnyException {\n 5 return createValue(key);\n 6 }\n 7 });\n 8 ...\n 9 try {\n10 return cache.get(key);\n11 } catch (ExecutionException e) {\n12 throw new OtherException(e.getCause());\n13 } "}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"设置最大存储"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Guava Cache"},{"type":"text","marks":[{"type":"strong"}],"text":"可以在构建缓存对象时指定缓存所能够存储的最大记录数量"},{"type":"text","text":"。当Cache中的记录数量达到最大值后再调用"},{"type":"text","marks":[{"type":"strong"}],"text":"put"},{"type":"text","text":"方法向其中添加对象,"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Guava"},{"type":"text","text":"会先从"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"当前缓存"},{"type":"text","text":"的"},{"type":"text","marks":[{"type":"strong"}],"text":"对象记录"},{"type":"text","text":"中选择"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"一条删除"},{"type":"text","text":"掉,腾出空间后再将新的对象存储到Cache中。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) {\n 3 Cache cache = CacheBuilder.newBuilder()\n 4 .maximumSize(2).build();\n 6 cache.put(\"key1\",\"value1\");\n 7 cache.put(\"key2\",\"value2\");\n 8 cache.put(\"key3\",\"value3\");\n 9 System.out.println(\"第一个值:\" + cache.getIfPresent(\"key1\"));\n10 System.out.println(\"第二个值:\" + cache.getIfPresent(\"key2\"));\n11 System.out.println(\"第三个值:\" + cache.getIfPresent(\"key3\"));\n12 }\n13 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 上面代码在构造缓存对象时,通过CacheBuilder类的maximumSize方法指定Cache最多可以存储两个对象,然后调用"},{"type":"text","marks":[{"type":"strong"}],"text":"Cache"},{"type":"text","text":"的"},{"type":"text","marks":[{"type":"strong"}],"text":"put"},{"type":"text","text":"方法向其中添加了三个对象。程序执行结果如下图所示,可以看到第三条对象记录的插入,导致了第一条对象记录被删除。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/11/114431e04eb8fe0beb1039f7e635b04d.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"设置过期时间"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 构建"},{"type":"text","marks":[{"type":"strong"}],"text":"Cache"},{"type":"text","text":"对象时,可以通过"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"CacheBuilder"},{"type":"text","text":"类的"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterAccess"},{"type":"text","text":"和"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterWrite"},{"type":"text","text":"两个方法为缓存中的对象指定过期时间,"},{"type":"text","marks":[{"type":"strong"}],"text":"使用`"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"CacheBuilder"},{"type":"text","marks":[{"type":"strong"}],"text":"`构建的缓存不会“自动”执行清理和逐出值,"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"也不会在值到期后立即执行或逐出任何类型。"},{"type":"text","marks":[{"type":"strong"}],"text":"相反,它在写入操作期间执行少量维护,或者在写入很少的情况下偶尔执行读取操作。"},{"type":"text","text":"其中,"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterWrite"},{"type":"text","text":"方法指定对象被写入到缓存后多久过期,"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterAccess"},{"type":"text","text":"指定对象多久没有被访问后过期。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws InterruptedException {\n 3 Cache cache = CacheBuilder.newBuilder()\n 4 .maximumSize(2)\n 5 .expireAfterWrite(3,TimeUnit.SECONDS)\n 6 .build();\n 7 cache.put(\"key1\",\"value1\");\n 8 int time = 1;\n 9 while(true) {\n10 System.out.println(\"第\" + time++ + \"次取到key1的值为:\" + cache.getIfPresent(\"key1\"));\n11 Thread.sleep(1000);\n12 }\n13 }\n14 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 上面的代码在构造Cache对象时,通过CacheBuilder的expireAfterWrite方法指定put到Cache中的对象在3秒后会过期。在Cache对象中存储一条对象记录后,每隔1秒读取一次这条记录。程序运行结果如下图所示,可以看到,前三秒可以从Cache中获取到对象,超过三秒后,对象从Cache中被自动删除。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b5/b599d3f4cb2c1a12ccb8472d0a003cf0.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"下面代码是expireAfterAccess的例子。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws InterruptedException {\n 3 Cache cache = CacheBuilder.newBuilder()\n 4 .maximumSize(2)\n 5 .expireAfterAccess(3,TimeUnit.SECONDS)\n 6 .build();\n 7 cache.put(\"key1\",\"value1\");\n 8 int time = 1;\n 9 while(true) {\n10 Thread.sleep(time*1000);\n11 System.out.println(\"睡眠\" + time++ + \"秒后取到key1的值为:\" + cache.getIfPresent(\"key1\"));\n12 }\n13 }\n14 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 通过CacheBuilder的"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterAccess"},{"type":"text","text":"方法指定Cache中存储的对象如果超过3秒没有被访问就会过期。while中的代码每sleep一段时间就会访问一次Cache中存储的对象key1,每次访问key1之后下次sleep的时间会加长一秒。程序运行结果如下图所示,从结果中可以看出,当超过3秒没有读取key1对象之后,该对象会自动被Cache删除。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/68/68d2a7d3bcd97b0dcb9188b129417287.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 也可以同时用"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterAccess"},{"type":"text","text":"和"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"expireAfterWrite"},{"type":"text","text":"方法指定过期时间,这时只要对象满足两者中的一个条件就会被自动过期删除。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Guava Cache缓存过期后不一定会立马被清理,一般会在Cache整体被读取一定次数后清理。这中策略对性能是有好处的,如果想强制清理可以手动调用`Cache.cleanup()`或者使用`"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"ScheduledExecutorService"},{"type":"text","text":"`来完成定期清理"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"弱引用"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 可以通过"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"weakKeys"},{"type":"text","text":"和"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"weakValues"},{"type":"text","text":"方法指定"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","text":"只保存对缓存记录"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"key"},{"type":"text","text":"和"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"value"},{"type":"text","text":"的弱引用。这样当没有其他强引用指向key和value时,key和value对象就会被垃圾回收器回收。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws InterruptedException {\n 3 Cache cache = CacheBuilder.newBuilder()\n 4 .maximumSize(2)\n 5 .weakValues()\n 6 .build();\n 7 Object value = new Object();\n 8 cache.put(\"key1\",value);\n10 value = new Object();//原对象不再有强引用\n11 System.gc();\n12 System.out.println(cache.getIfPresent(\"key1\"));\n13 }\n14 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 上面代码的打印结果是"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"null"},{"type":"text","text":"。构建"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","text":"时通过"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"weakValues"},{"type":"text","text":"方法指定"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","text":"只保存记录值的一个弱引用。当给value引用赋值一个新的对象之后,就不再有任何一个强引用指向原对象。System.gc()"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"触发垃圾回收后,原对象就被清除了。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"显示清除"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":" 可以调用Cache的"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"invalidateAll"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"或"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"invalidate"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"方法显示删除"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"中的记录。"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"invalidate"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"方法一次只能删除"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"中一个记录,接收的参数是要删除记录的key。"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"invalidateAll"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"方法可以批量删除"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"中的记录,当没有传任何参数时,"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"invalidateAll"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"方法将清除Cache中的全部记录。"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"invalidateAll"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"也可以接收一个"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Iterable"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}}],"text":"类型的参数,参数中包含要删除记录的所有key值。下面代码对此做了示例。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws InterruptedException {\n 3 Cache cache = CacheBuilder.newBuilder().build();\n 4 Object value = new Object();\n 5 cache.put(\"key1\",\"value1\");\n 6 cache.put(\"key2\",\"value2\");\n 7 cache.put(\"key3\",\"value3\");\n 9 List list = new ArrayList();\n10 list.add(\"key1\");\n11 list.add(\"key2\");\n13 cache.invalidateAll(list);\n\t\t\t\t\t //批量清除list中全部key对应的记录\n14 System.out.println(cache.getIfPresent(\"key1\"));\n15 System.out.println(cache.getIfPresent(\"key2\"));\n16 System.out.println(cache.getIfPresent(\"key3\"));\n17 }\n18 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 代码中构造了一个集合list用于保存要删除记录的key值,然后调用invalidateAll方法批量删除key1和key2对应的记录,只剩下key3对应的记录没有被删除。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"移除监听器"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 可以为"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"Cache"},{"type":"text","text":"对象添加一个"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"移除监听器"},{"type":"text","text":",这样当有记录被"},{"type":"text","marks":[{"type":"color","attrs":{"color":"#F5222D","name":"red"}},{"type":"strong"}],"text":"删除"},{"type":"text","text":"时可以感知到这个事件。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws InterruptedException {\n 3 RemovalListener listener = new RemovalListener() {\n 4 public void onRemoval(RemovalNotification notification) {\n 5 System.out.println(\"[\" + notification.getKey() + \":\" + notification.getValue() + \"] is removed!\");\n 6 }\n 7 };\n 8 Cache cache = CacheBuilder.newBuilder()\n 9 .maximumSize(3)\n10 .removalListener(listener).build();\n12 Object value = new Object();\n13 cache.put(\"key1\",\"value1\");\n14 cache.put(\"key2\",\"value2\");\n15 cache.put(\"key3\",\"value3\");\n16 cache.put(\"key4\",\"value3\");\n17 cache.put(\"key5\",\"value3\");\n18 cache.put(\"key6\",\"value3\");\n19 cache.put(\"key7\",\"value3\");\n20 cache.put(\"key8\",\"value3\");\n21 }\n22 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" "},{"type":"text","marks":[{"type":"strong"}],"text":"removalListener"},{"type":"text","text":"方法为"},{"type":"text","marks":[{"type":"strong"}],"text":"Cache"},{"type":"text","text":"指定了一个移除监听器,这样当有记录从Cache中被删除时,监听器"},{"type":"text","marks":[{"type":"strong"}],"text":"listener"},{"type":"text","text":"就会感知到这个事件。程序运行结果如下图所示。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ba/baebea5f55c4d6bdd36aa7a4412ab50d.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"自动加载"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Cache的get方法有两个参数,第一个参数是要从Cache中获取记录的key,第二个记录是一个Callable对象。当缓存中已经存在key对应的记录时,get方法直接返回key对应的记录。如果缓存中不包含key对应的记录,Guava会启动一个线程执行Callable对象中的call方法,call方法的返回值会作为key对应的值被存储到缓存中,并且被get方法返回。下面是一个多线程的例子:"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 3 private static Cache cache = CacheBuilder.newBuilder()\n 4 .maximumSize(3)\n 5 .build();\n 7 public static void main(String[] args) throws InterruptedException {\n 9 new Thread(new Runnable() {\n10 public void run() {\n11 System.out.println(\"thread1\");\n12 try {\n13 String value = cache.get(\"key\", new Callable() {\n14 public String call() throws Exception {\n15 System.out.println(\"load1\"); //加载数据线程执行标志\n16 Thread.sleep(1000); //模拟加载时间\n17 return \"auto load by Callable\";\n18 }\n19 });\n20 System.out.println(\"thread1 \" + value);\n21 } catch (ExecutionException e) {\n22 e.printStackTrace();\n23 }\n24 }\n25 }).start();\n27 new Thread(new Runnable() {\n28 public void run() {\n29 System.out.println(\"thread2\");\n30 try {\n31 String value = cache.get(\"key\", new Callable() {\n32 public String call() throws Exception {\n33 System.out.println(\"load2\"); //加载数据线程执行标志\n34 Thread.sleep(1000); //模拟加载时间\n35 return \"auto load by Callable\";\n36 }\n37 });\n38 System.out.println(\"thread2 \" + value);\n39 } catch (ExecutionException e) {\n40 e.printStackTrace();\n41 }\n42 }\n43 }).start();\n44 }\n45 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 这段代码中有两个线程共享同一个Cache对象,两个线程同时调用get方法获取同一个key对应的记录。由于key对应的记录不存在,所以两个线程都在get方法处阻塞。此处在call方法中调用Thread.sleep(1000)模拟程序从外存加载数据的时间消耗。代码的执行结果如下图:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6e/6ec4487867662cc765eaefcaf3783320.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 从结果中可以看出,虽然是两个线程同时调用"},{"type":"text","marks":[{"type":"strong"}],"text":"get"},{"type":"text","text":"方法,但只有一个"},{"type":"text","marks":[{"type":"strong"}],"text":"get"},{"type":"text","text":"方法中的"},{"type":"text","marks":[{"type":"strong"}],"text":"Callable"},{"type":"text","text":"会被执行(没有打印出"},{"type":"text","marks":[{"type":"strong"}],"text":"load2"},{"type":"text","text":")。"},{"type":"text","marks":[{"type":"strong"}],"text":"Guava"},{"type":"text","text":"可以保证当有多个线程同时访问"},{"type":"text","marks":[{"type":"strong"}],"text":"Cache"},{"type":"text","text":"中的一个"},{"type":"text","marks":[{"type":"strong"}],"text":"key"},{"type":"text","text":"时,如果"},{"type":"text","marks":[{"type":"strong"}],"text":"key"},{"type":"text","text":"对应的记录不存在,"},{"type":"text","marks":[{"type":"strong"}],"text":"Guava"},{"type":"text","text":"只会启动一个线程执行"},{"type":"text","marks":[{"type":"strong"}],"text":"get"},{"type":"text","text":"方法中"},{"type":"text","marks":[{"type":"strong"}],"text":"Callable"},{"type":"text","text":"参数对应的任务加载数据存到缓存。当加载完数据后,任何线程中的get方法都会获取到key对应的值。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"统计信息"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 可以对Cache的命中率、加载数据时间等信息进行统计。在构建Cache对象时,可以通过CacheBuilder的recordStats方法开启统计信息的开关。开关开启后Cache会自动对缓存的各种操作进行统计,调用Cache的stats方法可以查看统计后的信息。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws InterruptedException {\n 3 Cache cache = CacheBuilder.newBuilder()\n 4 .maximumSize(3)\n 5 .recordStats() //开启统计信息开关\n 6 .build();\n 7 cache.put(\"key1\",\"value1\");\n 8 cache.put(\"key2\",\"value2\");\n 9 cache.put(\"key3\",\"value3\");\n10 cache.put(\"key4\",\"value4\");\n12 cache.getIfPresent(\"key1\");\n13 cache.getIfPresent(\"key2\");\n14 cache.getIfPresent(\"key3\");\n15 cache.getIfPresent(\"key4\");\n16 cache.getIfPresent(\"key5\");\n17 cache.getIfPresent(\"key6\");\n19 System.out.println(cache.stats()); //获取统计信息\n20 }\n21 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"程序执行结果如下图所示:"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/29/2989393d56e031314b7d8522ee15d4a6.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 这些统计信息对于调整缓存设置是至关重要的,在性能要求高的应用中应该密切关注这些数据"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"LoadingCache"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" LoadingCache是Cache的子接口,相比较于Cache,当从LoadingCache中读取一个指定key的记录时,如果该记录不存在,则LoadingCache可以自动执行加载数据到缓存的操作。LoadingCache接口的定义如下:"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public interface LoadingCache extends Cache, Function {\n 2 \n 3 V get(K key) throws ExecutionException;\n 4 \n 5 V getUnchecked(K key);\n 6 \n 7 ImmutableMap getAll(Iterable extends K> keys) throws ExecutionException;\n 9 V apply(K key);\n10 \n11 void refresh(K key);\n12 \n13 @Override\n14 ConcurrentMap asMap();\n15 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 与构建Cache类型的对象类似,LoadingCache类型的对象也是通过CacheBuilder进行构建,不同的是,在调用CacheBuilder的build方法时,必须传递一个CacheLoader类型的参数,CacheLoader的load方法需要我们提供实现。当调用LoadingCache的get方法时,如果缓存不存在对应key的记录,则CacheLoader中的load方法会被自动调用从外存加载数据,load方法的返回值会作为key对应的value存储到LoadingCache中,并从get方法返回。"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":" 1 public class StudyGuavaCache {\n 2 public static void main(String[] args) throws ExecutionException {\n 3 CacheLoader loader = new CacheLoader () {\n 4 public String load(String key) throws Exception {\n 5 Thread.sleep(1000); //休眠1s,模拟加载数据\n 6 System.out.println(key + \" is loaded from a cacheLoader!\");\n 7 return key + \"'s value\";\n 8 }\n 9 };\n11 LoadingCache loadingCache = CacheBuilder.newBuilder()\n12 .maximumSize(3)\n13 .build(loader);//在构建时指定自动加载器\n15 loadingCache.get(\"key1\");\n16 loadingCache.get(\"key2\");\n17 loadingCache.get(\"key3\");\n18 }\n19 }"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"程序执行结果如下图所示:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/31/311ea4cbd7add8bb9ea2309a06186921.jpeg","alt":"","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章