Thuta Learning
How Mobile Apps Work
IntermediateMobile Developmentintermediate

မိုဘိုင်း Data: Local Storage, Offline, Sync

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • မိုဘိုင်း Data: Local Storage, Offline, Sync concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • Diagram/checklist ကို ဖတ်ပြီး mobile architecture/decision ဘယ်လို ဆက်စပ်နေသလဲ ခြေရာခံနိုင်ရန်
  • ကိုယ့် mobile app project အတွက် ဘယ်လို အသုံးချသင့်သလဲ ရှင်းပြနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Data ကို local သိမ်းထားတဲ့ app တိုင်းဟာ storage type, offline behavior, sync reconciliation ဆိုတဲ့ architectural decision အများကြီးကို ချမှတ်နေတာဖြစ်ပြီး framework အားလုံး underneath concept တူညီပါတယ်။

Conceptရှင်းလင်းချက်
Local Storagepreferences, cached data, drafts နှင့် ကိုက်ညီသည် — ဆုံးရှုံးရင်တောင် ကပျက်ကြေမဖြစ်ပါ။
Secure Storageauthentication token/credential အတွက် Keystore/Keychain ကဲ့သို့ platform-provided mechanism ကို သုံးရမည်။
Cachingremote data ကို local သိမ်းပြီး ချက်ချင်းပြသကာ background မှာ တိတ်တဆိတ် refresh လုပ်ခြင်း။
Offline Modenetwork မရှိချိန် blank error screen အစား local cache ဆီ fallback လုပ်ခြင်း (support ရှိပါက)။

Sync ဟာ အခက်ခဲဆုံး concept ဖြစ်သည် — data တူညီတစ်ခုကို offline ပြောင်းလဲမှုနှစ်ခုဟာ conflict ဖြစ်နိုင်ပြီး "online ရင် upload ရုံပဲ" ဆိုတာထက် ပိုရှုပ်ထွေးသည်။

Secure Storage
Android ရဲ့ Keystore-backed encrypted storage, iOS ရဲ့ Keychain ကဲ့သို့ sensitive data (token, credential) ကို extraction ခံနိုင်ရည်ရှိအောင် သိမ်းဆည်းပေးသည့် platform-provided mechanism။
Conflict Resolution
data တူညီတစ်ခုကို ပြောင်းလဲမှုနှစ်ခု ဝိရောဓိဖြစ်နေချိန် ဘယ် version နိုင်မလဲ (သို့) ဘယ်လို ပေါင်းစပ်မလဲ ဆုံးဖြတ်ပေးသည့် strategy (last-write-wins, server-authoritative, merge, manual)။
text
OFFLINE-FIRST DATA FLOW
-----------------------
OFFLINE-FIRST DATA FLOW
-----
Local change made (e.g. edit a note)
        |
        v
   Add change to sync queue
        |
        v
   Network available? ----No----> Use local cache, retry later
        |
       Yes
        |
        v
   Sync queued changes to server
        |
        v
   Conflicts found? ----No----> Local cache updated, done
        |
       Yes
        |
        v
Resolve (last-write-wins / server-authoritative / merge / manual)

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

notes app တစ်ခုမှာ note တူတူကို ဖုန်းက offline edit လုပ်ခဲ့ပြီး laptop ကလည်း edit လုပ်ခဲ့တယ်ဆိုပါစို့ — reconnect ဖြစ်လာချိန် app ဟာ real conflict နှင့် ရင်ဆိုင်ရပါလိမ့်မယ်။

StrategyTradeoff
Last-Write-Winsရိုးရှင်းသော်လည်း timestamp အသစ်ဆုံးမဟုတ်တဲ့ real work ကို တိတ်တဆိတ် ဖျက်ချနိုင်သည်။
Server-Authoritativeconsistency အတွက် ဘေးကင်းသော်လည်း local edit ဆုံးရှုံးသွားတဲ့ user အတွက် စိတ်ပျက်စရာ။
Mergeconflict မဖြစ်တဲ့ အပိုင်းများကို auto-combine ပြီး manual resolution ကတော့ user ကိုယ်တိုင် ရွေးချယ်ခိုင်းသည်။

App တိုင်းအတွက် correct strategy တစ်ခုတည်း မရှိပါဘူး — to-do app တစ်ခုဟာ last-write-wins ကို လက်ခံနိုင်ပေမယ့် collaborative document tool ကတော့ merge-based sync ပိုလိုအပ်ပါတယ်။

အတူတူ စမ်းရေးကြည့်မယ်

javascript
function chooseStorageType(data) {
  const { isSensitiveCredential, isUserPreference, isCachedContent } = data;
  if (isSensitiveCredential) return "secure storage (Keychain/Keystore-backed)";
  if (isCachedContent) return "cache (fetched remote data, safe to lose or refetch)";
  if (isUserPreference) return "normal local storage";
  return "normal local storage (default for uncategorized local data)";
}

const authToken = { isSensitiveCredential: true, isUserPreference: false, isCachedContent: false };
const fetchedArticleList = { isSensitiveCredential: false, isUserPreference: false, isCachedContent: true };
const darkModeSetting = { isSensitiveCredential: false, isUserPreference: true, isCachedContent: false };
const unsavedDraftNote = { isSensitiveCredential: false, isUserPreference: false, isCachedContent: false };

console.log("Auth token:", chooseStorageType(authToken));
console.log("Fetched article list:", chooseStorageType(fetchedArticleList));
console.log("Dark mode setting:", chooseStorageType(darkModeSetting));
console.log("Unsaved draft note:", chooseStorageType(unsavedDraftNote));
You should see
Auth token: secure storage (Keychain/Keystore-backed)
Fetched article list: cache (fetched remote data, safe to lose or refetch)
Dark mode setting: normal local storage
Unsaved draft note: normal local storage (default for uncategorized local data)

sensitive credential တစ်ခုတည်းက secure storage ဆီ ရောက်ပြီး၊ cached content ကတော့ cache category ဆီ ရောက်ကြောင်း ကြည့်ပါ။

၅ မိနစ် စမ်းကြည့်

`chooseStorageType` ထဲ ပဉ္စမ boolean `isDraftContent` တစ်ခု ထပ်ထည့်ပြီး ကိုယ်တိုင်ဆုံးဖြတ်ပါ — draft တစ်ခုဟာ cached content အုပ်စုတည်းမှာ ရှိသင့်လား၊ (သို့) သီးခြား အဖြေတစ်ခု ထိုက်တန်ပါသလား။ ဆုံးဖြတ်ချက်ကို ကိုက်ညီအောင် function ကို ပြောင်းလဲပါ။

သတိလေးတစ်ချက်

Authentication token (သို့) credential ကို plain generic local storage ထဲမှာ သိမ်းထားခြင်း (secure storage မသုံးဘဲ)

"online ရင် upload ရုံပဲ" လို့ ယူဆပြီး conflict resolution strategy ကို လုံးဝ မစဉ်းစားထားခြင်း

Data synchronization — WikipediaHow Mobile Apps Work

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Authentication token (သို့) credential ကို plain generic local storage ထဲမှာ သိမ်းထားခြင်း (secure storage မသုံးဘဲ)
  • "online ရင် upload ရုံပဲ" လို့ ယူဆပြီး conflict resolution strategy ကို လုံးဝ မစဉ်းစားထားခြင်း
  • ဒီ course က Android Development, Flutter, iOS Development, React Native tutorial တွေကို ထပ်မသင်ပါ — framework hands-on depth အတွက် အဲဒီ course တွေဆီ ဆက်သွားပါ။ ဒီ course က framework-neutral mobile architecture, decision-making, build/deployment/security concept တွေကိုသာ သင်ပေးပါတယ်။

လေ့ကျင့်ခန်း

`chooseStorageType` ထဲ ပဉ္စမ boolean `isDraftContent` တစ်ခု ထပ်ထည့်ပြီး ကိုယ်တိုင်ဆုံးဖြတ်ပါ — draft တစ်ခုဟာ cached content အုပ်စုတည်းမှာ ရှိသင့်လား၊ (သို့) သီးခြား အဖြေတစ်ခု ထိုက်တန်ပါသလား။ ဆုံးဖြတ်ချက်ကို ကိုက်ညီအောင် function ကို ပြောင်းလဲပါ။

You'll know it worked when: Auth token: secure storage (Keychain/Keystore-backed) Fetched article list: cache (fetched remote data, safe to lose or refetch) Dark mode setting: normal local storage Unsaved draft note: normal local storage (default for uncategorized local data) sensitive credential တစ်ခုတည်းက secure storage ဆီ ရောက်ပြီး၊ cached content ကတော့ cache category ဆီ ရောက်ကြောင်း ကြည့်ပါ။

မိုဘိုင်း Data: Local Storage, Offline, Sync | Thuta Learning