mitchtabian/Local-db-Cache-Retrofit-REST-API-MVVM
App that interacts with a REST API using Retrofit. There is a local db cache and architecture is MVVM
📱 Local Database Cache với REST API, Retrofit2 & MVVM
Một khoá học thực hành đầy đủ về cách xây dựng cache cơ sở dữ liệu cục bộ cho ứng dụng Android — từ thiết kế schema Room, gọi API Retrofit, đến chiến lược đọc/ghi thông minh khi mạng không ổn định.
Dự án này là mã nguồn đi kèm khoá học "Local Database Cache with REST API, Retrofit2, MVVM Architecture" của Mitch Tabian (codingwithmitch.com). Nó demo một ứng dụng Android hoàn chỉnh sử dụng kiến trúc MVVM (Model-View-ViewModel) kết hợp Room Persistence Library làm cache SQLite, Retrofit2 gọi REST API, và LiveData quan sát thay đổi dữ liệu. Mục tiêu cốt lõi: cho phép ứng dụng hoạt động mượt mà khi offline, đồng bộ dữ liệu khi có mạng, và minh hoạ tại sao cache cấp cơ sở dữ liệu (Room) thường linh hoạt/hiệu quả hơn cache HTTP thuần túy của Retrofit/OkHttp.
✨ Điểm nổi bật
- Cache offline với Room/SQLite: Lưu phản hồi API vào cơ sở dữ liệu cục bộ để đọc khi mất mạng.
- Truy vấn SQLite tuỳ chỉnh qua Room DAO: Viết query phức tạp (join, filter, pagination) thay vì chỉ cache nguyên bản JSON.
- Tuỳ chỉnh TTL (time-to-live) cache: Kiểm soát dữ liệu sống bao lâu trước khi coi là lỗi thời và cần fetch lại.
- So sánh chiến lược cache Retrofit vs Room: Phân tích ưu/nhược điểm — Retrofit/OkHttp cache phù hợp response nguyên vẹn, Room phù hợp truy vấn có cấu trúc, lọc, liên kết bảng.
- Glide Image Caching & RecyclerView Preloader: Cấu hình cache hình ảnh, preload số lượng item tuỳ ý để cuộn mượt.
- Xử lý lỗi mạng & timeout OkHttp: Cấu hình timeout, retry, và fallback về cache khi request thất bại.
- Chuyển Retrofit Call → LiveData (Call Adapter): Tích hợp luồng bất đồng bộ vào vòng đời ViewModel/LiveData tự nhiên.
- Kiến trúc MVVM chuẩn Jetpack: ViewModel, Repository, LiveData, Room, Retrofit tách biệt rõ ràng.
💡 Vì sao đáng chú ý
Dự án không chỉ demo "cách dùng Room" mà đi sâu vào thiết kế cache — một chủ đề thường bị lướt qua trong các tutorial cơ bản. Nó chỉ ra không có giải pháp "one size fits all": cache HTTP (Retrofit/OkHttp) tốt cho response tĩnh, toàn vẹn; cache Room tốt cho dữ liệu cần truy vấn, lọc, quan hệ, hoặc khi muốn kiểm soát細粒度 (granular) hơn vòng đời dữ liệu. Phần Glide RecyclerView Preloader cũng rất thực tế cho danh sách hình ảnh lớn. Phù hợp làm tài liệu tham khảo khi bạn cần triển khai chế độ offline-first hoặc hybrid cache cho app Android production.
#Android #MVVM #RoomDatabase #Retrofit2 #OfflineFirst #TiniX
Dự án tương tự
Khám phá các dự án và mô hình AI khác có sự tương đồng.
🍲Foodium is a sample food blog Android application 📱 built to demonstrate the use of Modern Android development tools - (Kotlin, Coroutines, Flow, Dagger 2/Hilt, Architecture Components, MVVM, Room, Retrofit, Moshi, Material Components).
🔥🔥🔥 Kotlin + MVVM + LCE版玩安卓,暗黑模式、横竖屏、无网、弱网、无数据、加载失败等等各种情况,协程、Room、Hilt、DataStore、LiveData、Retrofit、屏幕适配、本地缓存、多语言切换、多 lib,你想要的我都有!!!
👕基于谷歌最新AAC架构,MVVM设计模式的一套快速开发库,整合Okhttp+RxJava+Retrofit+Glide等主流模块,满足日常开发需求。使用该框架可以快速开发一个高质量、易维护的Android应用。
💎 Android application following best practices: Kotlin, Coroutines, JetPack, Clean Architecture, Feature Modules, Tests, MVVM, DI, Static Analysis...
SwiftUI sample app using Clean Architecture. Examples of working with SwiftData persistence, networking, dependency injection, unit testing, and more.
Template iOS app using Clean Architecture and MVVM. Includes DIContainer, FlowCoordinator, DTO, Response Caching and one of the views in SwiftUI
Voice AI SDK is a reusable Android library that gives any app a full voice-driven AI conversation pipeline in minutes. Voice Assistant + Android Voide AI + SDK + MVVM + Kotlin