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}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章