Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Javaユーザに伝えたいGuava Cache入門
Search
Hiroto YAMAKAWA
January 15, 2017
Technology
0
1.4k
Javaユーザに伝えたいGuava Cache入門
Java Do #08
https://javado.connpass.com/event/47668/
Hiroto YAMAKAWA
January 15, 2017
Tweet
Share
More Decks by Hiroto YAMAKAWA
See All by Hiroto YAMAKAWA
Javaへの新たなHello, World / yuruchitose-04
gishi_yama
0
31
JSR381、知っていますか?Javaの画像認識APIのはなし / SC4Y23-05
gishi_yama
0
180
jPeekでのクラスの凝集度計測の試行 / mild-web-sapporo#24
gishi_yama
0
310
Github CopilotとChatGPTを使って感じた使い分けの糸口 / JavaDo #22
gishi_yama
1
1.3k
子ども向けプログラミング体験教室でのHololens2利用事例 / IoTLT#97
gishi_yama
0
87
AWS Serverless Java Container, Spring Bootで試してみた / javado22
gishi_yama
0
480
Hololens2と 小中高プログラミング教育の利用にむけた試行 / XRMTG 2023-1-18
gishi_yama
0
280
小学生がmicro:bitを用いて行える課題解決を意識した自由研究事例 /SC4Y '22#4
gishi_yama
0
380
あなたもこだわろう!Web開発環境 (物理編)'22 / mild-web-sapporo#22
gishi_yama
0
300
Other Decks in Technology
See All in Technology
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
110
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
610
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
940
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
290
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
240
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
650
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Docker and Python
trallard
40
3.1k
A better future with KSS
kneath
238
17k
Making Projects Easy
brettharned
115
5.9k
KATA
mclloyd
29
14k
Designing the Hi-DPI Web
ddemaree
280
34k
Statistics for Hackers
jakevdp
796
220k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
What's in a price? How to price your products and services
michaelherold
243
12k
Transcript
!HJTIJ@ZBNB +BWBϢʔβʹ͍͑ͨ (VBWB$BDIFೖ
IUUQTDPEFSEPKPTBQQPSPDPOOQBTTDPNFWFOU
&BSMZ IUUQXXXUPPDPNTVQQPSUBQQMFOFXTIUNM জᢣᦍᣀ
όεϩέʔγϣϯγεςϜͷ։ൃʹͯ ᣪఞⷭӒҵヹ➥ᕕӒҵѬᥥ㛯ᏌҶ৵ҮԯդԧӼ Ტ༪%#ҵӳ4FMFDUҿӅӵԛԡӬӍӉҮӔҮӲҰӔҶӃӵ ȤѫԕՋԫԟՍӁӐөӵҵ
ǖ +BWBӘԕՋԫԟՍՑԌԾՑՒ (PPHMFӘ+BWB᳣⇹ՑԌԾՑՒ(VBWBӘकᮿ⥎㮣 ǖ ⼀ᇰԽԉԌՓՔԡ㮢ԛդԱञӑ⼀ᇰ㮣ӑಌਃ ǖ IUUQTHJUIVCDPNHPPHMFHVBWBXJLJ$BDIFT&YQMBJOFE ǖ NBWFO (VBWB$BDIF
EFQFOEFODZ HSPVQ*EDPNHPPHMFHVBWBHSPVQ*E BSUJGBDU*EHVBWBBSUJGBDU*E WFSTJPOWFSTJPO EFQFOEFODZ
αϯϓϧɿΩʔΛ༩͑ΔͱࣗಈతʹΩϟογϡσʔλΛੜ LoadingCache<String, Integer> randomIntCache = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.SECONDS) .build(new CacheLoader<String,
Integer>() { @Override public Integer load(String key) throws Exception { return getRandomInt(); } }); HFU ǒGPPǒ ӑѬMPBE ǒGPPǒ Әᇴ✿᧠ӼǒGPPǒӒҮҰԕդӑԕՋԫԟՍӃӵѭ ⓬ᒁӉӍӉӳѬԕՋԫԟՍӁӉԌ՛ԡԧ՛ԡӼ⏺᪨Ӄӵ Integer v1 = randomIntCache.get(”foo”); ← (1) loadϝιουΛ࣮ߦ͠ɺ݁ՌΛΩϟογϡ Integer v2 = randomIntCache.get(”foo”); ← (2) (1)ͷ࣮ߦ݁Ռͱશ͘ಉ͡ΠϯελϯεΛฦ͢
LoadingCache<String, Integer> randomIntCache = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.SECONDS) .build(new CacheLoader<String, Integer>()
{ @Override public Integer load(String key) throws Exception { return getRandomInt(); } }); ԕՋԫԟՍӘ⻎ᠶᦴঽӔӓ LFZ 7BMVF ԕՋԫԟՍӃӵ7BMVFྞԌ՛ԡԧ՛ԡӘ⇰ᘻᢅᴿѭ,FZӼਜӍӉⅈӑ⇰ᘻӬ൧⥎ѭ ,FZ 7BMVFәԗՑԡѭ $BDIF-PBEFSәѬ,FZҾӒӕԕՋԫԟՍӃӵ7BMVFԌ՛ԡԧ՛ԡӘ⇰ᘻᢅᴿӼఙᒐӃӵѭ ԕՋԫԟՍӘ⻎ᠶᦴঽӔӓә⹋ᡔ⼀ᇰӑҷӵѭ㮢ఙ㖟ᣪ㔿ѬԕդӘᡔӔӓ㮣 $BDIF-PEFSӼ ਜҰӒҷә -PBEJOH$BDIF αϯϓϧɿΩʔΛ༩͑ΔͱࣗಈతʹΩϟογϡσʔλΛੜ LFZ 7BMVF LFZ 7BMVF
αϯϓϧɿΩʔΛ༩͑ΔͱࣗಈతʹΩϟογϡσʔλΛੜ LoadingCache<String, Integer> randomIntCache = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.SECONDS) .build(CacheLoader.from(() ->
getRandomInt())); +BWBӘMBNCEBᐛ㮢'VODUJPO 4VQQMJFS㮣ӼਜӍӐ$BDIF-PBEFSӼਃӶӵѭѫ 'VODUJPO LFZ LFZӼਜҰⅈ 4VQQMJFS LFZӼਜӹӔҮⅈ -BNCEBᐛӼਜҰ൶Ѭ&YDFQUJPOҶԡՕդҿӶӔҮӘӑѬHFU6ODIFDLFE ,FZ ӼਜҰѭ 㮢⼳✦әᒁ㈨ѭӉӊӁHFUӘӨӨӑӬහӝ௲ӁӕਦႌⅈҶᒨ⺙ӔҽӒলႌәใ㛸әᾩҮ㮣 Integer v1 = randomIntCache.getUnchecked(”foo”); ← ExceptionͷνΣοΫΛ͠ͳ͍߹ Integer v2 = randomIntCache.getUnchecked(”foo”);
ΩϟογϡͰ͖Δσʔλͷߏɿ&OUSZ ,FZԌ՛ԡԧ՛ԡ 7BMVFԌ՛ԡԧ՛ԡ Ǒ"ǒ ǑҴәӲҰǒ Ǒ#ǒ ǑҽӽӕӋәǒ Ǒ$ǒ ǑҿӲҰӔӳǒ ,FZԌ՛ԡԧ՛ԡ
7BMVFԒԾԠԏԗ ǑBǒ ǑCǒ ǑDǒ ǑFǒ ǑGǒ ǑHǒ ǑIǒ ǑJǒ ǑKǒ ,FZԌ՛ԡԧ՛ԡ㮴7BMVFԌ՛ԡԧ՛ԡӘՂԊӼԐ՛ՒӒӁӐᩈ✊ӑҷӵѭ 㮢.BQӒൺӂ㮣 ȔԐ՛Ւ
ΤϯτϦͷഁغ݅ɿ&WJDUJPO ǖ FYQJSF"GUFS8SJUF MPOHEVSBUJPO 5JNF6OJUVOJU Ԑ՛ՒӼਃᘻӁӐҵӳ⏺᪨ҿӶӵӨӑӘᦆ㖟ѭ ǖ FYQJSF"GUFS"DDFTT MPOHEVSBUJPO
5JNF6OJUVOJU Ԑ՛ՒӕᥰᒁӘԊԗԣԡҶҬӍӐҵӳ⏺᪨ҿӶӵӨӑӘᦆ㖟ѭ ǖ NBYJNVN4J[F MPOHTJ[F Ԑ՛ՒӼᛝӃӵᡔѭᛡᇰᡔলञӘԐ՛ՒᡔӕӔӵӒѬ'*'0ӑ⏺᪨ѭ ǖ NBYJNVN8FJHIU㮢MPOHTJ[F Ԑ՛ՒӼᛝӃӵᡔѭৼҵҶᛡᇰলञӘᡔӕӔӵӒѬ'*'0ӑ⏺᪨ѭ ѷৼҵѸӘ☑௲ՓդՓә8FJHIFSԒԾԠԏԗӑḉӃѭ 㮢ਦҲӚѬԕՋԫԟՍӃӵ7BMVFӘ➜൶ᡡᆻᡔѬ-JTUᡔӔӓ㮣
ΤϯτϦͷഁغ݅ɿ3FGSFTI ǖ SFGSFTI"GUFS8SJUF MPOHEVSBUJPO 5JNF6OJUVOJU Ԑ՛ՒӼਃᘻӁӐҵӳӉӕ7BMVFӼᥥӁ⍃ӃӨӑӘᦆ㖟ѭ FYQJSF9999ӒӘ㉹Ү㮴 FYQJSFәѬᦴঽӼṅӉӃӒԐ՛ՒӼ⏺᪨Ӄӵ
⏺᪨ӘҬӒѬൺӂԕդӑHFUҿӶӵӒѬ7BMVFҶṍ૨ҿӶӵӨӑ⽠ө㈆өᑻӋӕӔӵ SFGSFTIәѬԕդӕሽӁӐӁҮ7BMVFӼṍ૨ӃӵӨӑѬ൜Ү7BMVFӼ㈘Ӂ❰һӵ 㮢⽠ө㈆өᑻӋӕӁӔҮ㮣
ͦͷ΄͔ͷઃఆɿΨϕʔδίϨΫγϣϯͱͷ݉Ͷ߹͍ ǖ TPGU7BMVFT WBMVFӼ4PGU3FGFSFODFӕӃӵ ǖ XFBL,FZT ,FZӼ8FBL3FGFSFODFӕӃӵ ǖ
XFBL7BMVFT WBMVFӼ8FBL3FGFSFODFӕӃӵ ԕդӬӁҹә7BMVFӼᐹീ῍㮢($ҿӶӮӃҹ㮣ӕӃӵѭ 8FBLӒ4PGUӘ㉹ҮәতӘねᡭӔӓӕ⽟ᣀӼӴӉҮҶѬ Ԍ՛ԡԧ՛ԡҶീ῍ҿӶӔҹӔӍӉ㗖Ә($ҿӶӮӃҿӒ⢰ҲӶӚӲҮ 㮢8FBLӘᢅҶ($ҿӶӮӃҹѬ4PGUӘᢅҶԕՋԫԟՍൿҷ㮣
αϯϓϧɿࣗͰΤϯτϦΛొ͢Δ Cache<String, Integer> origCache = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.SECONDS) .build(); ⧞ಌ⋵ӕ7BMVFӼՕդԱӁӔҮ$BDIFԌ՛ԧդԽԏդԡྞӘԕՋԫԟՍӼਃӴѬ
QVU LFZ 7BMVF㮣ӑѬ⧞ӑԐ՛ՒӼ⋭㑤ӃӵҽӒӬӑҷӵ &YQJSFӔӓӘ⼀ᇰӬ-PBEJOH$BDIFൺ᭦ѭ origCache.put(”foo”, 1); origCache.put(”bar”, 2); Integer v1 = origCache.getIfPresent(”foo”); $BDIF-PEFSӼਜӹӔҮӒҷә$BDIF
ΤϯτϦͷഁغɿJOWBMJEBUF $BDIF-PBEJOH$BDIFӘႁᡔӕᇴӑҷӵ ǖ JOWBMJEBUF LFZ ᛡᇰҿӶӉԕդӘԐ՛ՒӼ⏺᪨Ӄӵ ǖ JOWBMJEBUF"-- LFZT
ᛡᇰҿӶӉӐӘԕդӘԐ՛ՒӼ⏺᪨Ӄӵ ǖ JOWBMJEBUF"-- ӐӘԐ՛ՒӼ⏺᪨Ӄӵ
HFUͷछྨͱ͍͚ ǖ HFU ,LFZ -PBEJOH$BDIFӑѬLFZӕሽӃӵ7BMVFӼᒉӃӵѭ 7BMVFӘՕդԱसӕԐՑդҶ⋬⇰ӃӵӒѬ&YFDVUJPO&YDFQUJPOӼUISPXӃӵѭ ǖ HFU6ODIFDLFE ,LFZ
-PBEJOH$BDIFӑѬLFZӕሽӃӵ7BMVFӼᒉӃӵѭ HFUӒൺӂӊҶѬ$BDIF-PBEFSӑԩԏԫԗਦႌӼ⋬ӁӔҮ൶ӕਜҲӵѭ ਦ㮣$BDIF-PBEFSӑMBNCEBᐛӼਜҰᣪ ǖ HFU*G1SFTFOU 0CKFDULFZ $BDIFӑѬLFZӒӁӐᢡӕᆼཡӁӐҮӵӬӘҶҬӶӚ7BMVFӼᒉӃӵѭᾩһӶӚOVMMѭ ӇӘӥҵѬӐӘԐ՛ՒӼ.BQӒӁӐ㈘ӃBT.BQ HFU"MM1SFTFOUӔӓӬҬӵѭ
·ͱΊ (VBWB$BDIFӼਜҰӒѬᡔӑԊԿՒӕԕՋԫԟՍӘণ✵өӼ⇹ᖌӑҷӵѭ Ԑ՛Ւ㮢LFZӒWBMVFӘՂԊ㮣ҶԕՋԫԟՍҿӶѬLFZӑWBMVFӼහӝ௲Ӄѭ -PBEJOH$BDIFӑәѬLFZӕሽӃӵWBMVFӼ$BDIF-PBEFSӑ⇰ᘻӃӵѭ $BDIFӑәѬ⧞ӑLFZӕሽӃӵWBMVFӼQVUӃӵѭ FYQJSF9999 NBYJNVN9999SFGSFTI9999ӔӓӑѬ Ԑ՛ՒӘ⏺᪨ӮᥥӘᦆ㖟ӮᦴঽӼᴀӫӵҽӒҶ௲ᦸӵѭ
$BDIFӘ┣㜇Ӯ$BDIF-PBEFSӘਃӴᢅ ਦႌӘᾩ㮣ӑHFUӘᢅᴿҶႁӹӵ
αϯϓϧίʔυ IUUQTHJUIVCDPNHJTIJZBNBKBWBEP 4UBSUԗՑԡӼゼಌӁӐԾՑԎԞӑ⽇ӃӵҵѬ 0UIFS4BNQMFTԗՑԡӼಌਃҿӅӐҹӊҿҮѭ ⋬ⷭሉӘӐә➃⡣ӁӐҮӨӅӽҶѬᒁӑԝ՛ԿՓӒӁӐビӁӉҮӔӒᓤӍӐҮӨӃѭ ӨӉѬീ⢰ᡡ⃀ӘҶѬ⪙⽓ӑӃҶԛդԱਦҶӹҵӴӮӃҹ୦ᇴӁӐӨӃѭ
ࢀߟจݙ !LB[VIJSB@S+BWBӑਜҲӵԒդԿ՛ԥդԡգԕՋԫԟՍՑԌԾՑՒ IUUQEIBUFOBOFKQ,B[VIJSB !BLJSBLPZBTV㉜ೂӃӵ+BWBՑԌԾՑՒѬ(VBWB IUUQXXXBLJSBLPZBTVOFUHVBWBKBWB MJCSBSJFTFWPMWJOH !CBFMEVOH(VBWB$BDIF IUUQXXXCBFMEVOHDPNHVBWBDBDIF HPPHMF$BDIFT&YQMBJOFE IUUQTHJUIVCDPNHPPHMFHVBWBXJLJ$BDIFT&YQMBJOFE