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
In-Memory Realms を使って API キャッシュした話 / Use In-Mem...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
satoru.sasaki
June 29, 2018
Programming
1.8k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
In-Memory Realms を使って API キャッシュした話 / Use In-Memory Realms
satoru.sasaki
June 29, 2018
More Decks by satoru.sasaki
See All by satoru.sasaki
Dynamic Links with mitene
caad1229
0
1.9k
みてねのAndroid課金開発環境 / Android In-App Purchase Environment
caad1229
0
1.7k
Other Decks in Programming
See All in Programming
数百円から始めるRuby電子工作
tarosay
0
140
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
220
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
410
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
180
源内ハンズオン概要編
hideg
0
150
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
210
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
210
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
340
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
610
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
今さら聞けない .NET CLI
htkym
0
190
Featured
See All Featured
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
For a Future-Friendly Web
brad_frost
183
10k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
So, you think you're a good person
axbom
PRO
2
2.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
240
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.7k
From π to Pie charts
rasagy
0
260
Transcript
In-Memory Realms ͬͯ API Ωϟογϡͨ͠ ΈͯͶͷMeetup #1 2018-06-27 satoru.sasaki
ࣗݾհ —ࠤʑ ڿ (@caad1229) —201510݄ೖࣾ —ࡢ SNSϛΫγΟ -> ΈͯͶ ʹҠಈ
—झຯϨίʔυͰ Jazz ௌ͘͜ͱ
ΈͯͶΞϓϦͱrealm —ΈͯͶͰϢʔβͷϝσΟΞ ใΛ realm ͰΩϟογϡ͍ͯ͠ Δ —ࠩಉظͱશମಉظͰ realm ʹ ಉظ
—ىಈ࣌ɾ௨ड৴ɾΞοϓϩ ʔυ࣌
ΈͯͶΞϓϦͱ Architecutre —Android ͷ৽نػೳ MVVM Ͱ࣮ —iOS ͱઃܭΛἧ͑ΔͨΊʹ CleanArchitecture Λ͍ͬͯ
Δͱ͜Ζ͋Δ
API ΩϟογϡΛ͏ܦҢ —Ϣʔβͷʹ৮ΕΔػձ͕ଟ͍͕ɺߋ৽͕සൟͰͳ͍ —ը໘͕දࣔ͢Δͨͼʹ fetch ͢Δඞཁ͕ͳ͍ —Push ͳͲͰ࠷৽Λऔಘ͢Ε͍͍ఔ
In-memory Realm ʹ͍ͭͯ —σʔλϝϞϦॻ͔ΕΔ —Realm ΠϯελϯεͷࢀরΧϯλ͕ 0 ʹͳΔͱσ ʔλ͕ফ͑Δ —ΞϓϦىಈதͰσʔλΛอ͍࣋ͨ͠߹
Application ΫϥεͰ Realm ΠϯελϯεΛอ࣋
In-memory Realm ͷಋೖ —Application Ͱ realm ΠϯελϯεΛอ࣋ open class CustomApplication
: Application() { private var realm: Realm? = null : }
In-memory Realm ͷಋೖ —onCreate Ͱੜͱอ࣋ override fun onCreate() { super.onCreate()
val config = RealmConfiguration.Builder() .name("in-memory.realm") .inMemory() .build() // อ࣋͢Δ realm = Realm.getInstance(config) }
In-memory Realm ͷಋೖ —onTerminate Ͱഁغ override fun onTerminate() { realmInMemory?.close()
super.onTerminate() }
cache ػߏͷͨΊͷઃܭ —MVVM ͏
Data ͷѻ͍ —Mapper Λͬͯڞ௨ Object ʹ ͢Δ —Mapper ʹม͢Δ interface
Mapper<E, D> { fun mapFromEntity(type: E): D fun mapToEntity(type: D): E }
Cache ͷσʔλ —RealmObject —ϦϨʔγϣϯ͕؆୯ʹͰ͖Δ RealmList<T> Λ͏
Repository —Local ͱ Remote Λ͏ —cache ͷอଘͱऔಘϩδοΫ —Local ͔Βऔಘͯ͠ɺͳ͚Ε
Remote ͔Β fetch ͢Δ —ڧ੍తʹ Remote ͔Βऔಘ Ͱ͖ΔΑ͏ʹ͢Δ
Repository
Demonstration
Demonstration Qiita هࣄҰཡΛऔಘ͢ΔΞϓϦ https://github.com/caad1229/apicache dagger2 okHttp3 retrofit2 rxJava2 realm Glide
՝ͱ͔ —expire ͷλΠϛϯά —ΩϟογϡΫϦΞͷλΠϛϯά —ϖʔδϯάɾϢʔβૢ࡞ʹΑΔςʔϒϧͷߋ৽
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠