Upgrade to Pro — share decks privately, control downloads, hide ads and more …

In-Memory Realms を使って API キャッシュした話 / Use In-Memory Realms

In-Memory Realms を使って API キャッシュした話 / Use In-Memory Realms

satoru.sasaki

June 29, 2018
Tweet

More Decks by satoru.sasaki

Other Decks in Programming

Transcript

  1. In-memory Realm ͷಋೖ —onCreate Ͱੜ੒ͱอ࣋ override fun onCreate() { super.onCreate()

    val config = RealmConfiguration.Builder() .name("in-memory.realm") .inMemory() .build() // อ࣋͢Δ realm = Realm.getInstance(config) }
  2. Data ͷѻ͍ —Mapper Λ࢖ͬͯڞ௨ Object ʹ ͢Δ —Mapper ʹม׵͢Δ interface

    Mapper<E, D> { fun mapFromEntity(type: E): D fun mapToEntity(type: D): E }
  3. Repository —Local ͱ Remote Λ࢖͏ —cache ͷอଘͱऔಘϩδοΫ —Local ͔Βऔಘͯ͠ɺͳ͚Ε ͹

    Remote ͔Β fetch ͢Δ —ڧ੍తʹ Remote ͔Βऔಘ΋ Ͱ͖ΔΑ͏ʹ͢Δ