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
satoru.sasaki
June 29, 2018
Programming
0
1.7k
In-Memory Realms を使って API キャッシュした話 / Use In-Memory Realms
satoru.sasaki
June 29, 2018
Tweet
Share
More Decks by satoru.sasaki
See All by satoru.sasaki
Dynamic Links with mitene
caad1229
0
1.7k
みてねのAndroid課金開発環境 / Android In-App Purchase Environment
caad1229
0
1.6k
Other Decks in Programming
See All in Programming
AIプログラミング雑キャッチアップ
yuheinakasaka
1
420
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
450
さいきょうのレイヤードアーキテクチャについて考えてみた
yahiru
3
760
パスキーのすべて ── 導入・UX設計・実装の紹介 / 20250213 パスキー開発者の集い
kuralab
3
850
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
180
ファインディLT_ポケモン対戦の定量的分析
fufufukakaka
0
860
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
380
Honoとフロントエンドの 型安全性について
yodaka
7
1.4k
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.4k
Domain-Driven Transformation
hschwentner
2
1.9k
DROBEの生成AI活用事例 with AWS
ippey
0
140
color-scheme: light dark; を完全に理解する
uhyo
6
460
Featured
See All Featured
Building an army of robots
kneath
303
45k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Building Applications with DynamoDB
mza
93
6.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Why Our Code Smells
bkeepers
PRO
336
57k
Statistics for Hackers
jakevdp
797
220k
Building Adaptive Systems
keathley
40
2.4k
4 Signs Your Business is Dying
shpigford
182
22k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.8k
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 ͷλΠϛϯά —ΩϟογϡΫϦΞͷλΠϛϯά —ϖʔδϯάɾϢʔβૢ࡞ʹΑΔςʔϒϧͷߋ৽
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠