No video

Retrofit Caching Example and Why it SUCKS

  Рет қаралды 16,510

CodingWithMitch

CodingWithMitch

Күн бұрын

In this video I talk about Retrofit caching and why (in my opinion) you shouldn't use it. Even though I don't think you should use it, I still show you an example of how to set up it and cache http requests.
The reasons you shouldn't use Retrofit caching fall into a couple main categories:
1) It's extremely inefficient (because it uses a key/value pair system)
2) You can't do any kind of custom searching
3) It doesn't follow the single source of truth principal (see my video on the single source of truth principal here: • Single Source of Truth... )
SO WHAT'S THE ALTERNATIVE?
- SQLite and the Room Persistence Library!
➤ Caching course with Room, SQLite, MVVM, Retrofit, Pagination, and much more:
↻ codingwithmitc...
➤ Code for this video:
↻ github.com/mit...

Пікірлер: 59
@EklakDangaura
@EklakDangaura 5 жыл бұрын
Damn, this is fast. Just had a look at the repo this morning.. now the video. Thanks. :)
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I didn't think I'd do it until tomorrow, but I got inspired.
@syyamnoor9792
@syyamnoor9792 4 жыл бұрын
It doesn't suck, it's just the implementation that does. Why don't you use just hit one api to fetch all the data and store it in a list etc, and then cache it. For searching we can avoid using other api hits like photos/{id}, we can simply search from that cached list.
@codingwithmitch
@codingwithmitch 4 жыл бұрын
its shit. You should cache with room
@TBadalov
@TBadalov 3 ай бұрын
This doesn't make retrofit caching any less. What you were describing are two different layers of caching. One can still use room to cache complex data structures which are still eventually retrieved via API call. One doesn't contradict another
@JacobZinn-rs1we
@JacobZinn-rs1we Жыл бұрын
It's true... retrofit caching really does suck. I spent 4 hours on it and it never hit cache. I spent 1 hour on room and it works great!
@raghvendrasahu5596
@raghvendrasahu5596 2 жыл бұрын
cache not store using POST method. HTTP 504 Unsatisfiable Request (only-if-cached) error
@pradeepkumarreddykondreddy7048
@pradeepkumarreddykondreddy7048 3 жыл бұрын
when max-stale value set to less than 1 day, caching is not working. Any reason for that ?
@ikhiloyaimokhai9974
@ikhiloyaimokhai9974 3 жыл бұрын
Really great tutorial and explanation. When Room is used for caching, how often would the data be refreshed from the network?
@barakerzeonlist4608
@barakerzeonlist4608 5 жыл бұрын
I love your tutorial I'm learning java now just soon I'll be developer
@sergeyyjyakunin1514
@sergeyyjyakunin1514 3 жыл бұрын
Did you become a developer?
@RB-xx3xf
@RB-xx3xf 5 жыл бұрын
Very good job ! Thanks for the video !
@rudreshsp3236
@rudreshsp3236 3 жыл бұрын
how to cancel a retrofit request used in executor , plz share video
@zuhrulanam5971
@zuhrulanam5971 2 жыл бұрын
I cant force update new data, retrofit always caching I have tried with no cache and also force network. Thanks bro
@jegali
@jegali 4 жыл бұрын
Hi Mitch, I have to cache aurora forecast data from services.swpc.noaa.gov which is 2MB in size. I managed to download, parse and save the data as a String to the Room Database, but if I try to select the data from the database I am told the data is too big. Do you have any suggestions how to handle this?
@Daaaaaaavid
@Daaaaaaavid 2 жыл бұрын
Few years after and I used it, didn't understand why it should be so bad, if you cache it a db you also cache the whole response? My app loads a list from a rest api using retrofit, the caching works wonderfully, don't see the problem.
@salmanhameed9495
@salmanhameed9495 5 жыл бұрын
How to cache a post request using retrofit ?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
You can't
@codinginflow
@codinginflow 5 жыл бұрын
Wow I don't believe Square created this shit! I am disappointed and a little bit sad.
@abuzarshaikh3596
@abuzarshaikh3596 5 жыл бұрын
Great tutorial! cache can be modified or edited?
@fazalcs4820
@fazalcs4820 4 жыл бұрын
Mitch can you make the tutorial on Store library for storing data
@jesselima_dev
@jesselima_dev 5 жыл бұрын
Great advanced tips!!!
@highlightmatchoffootball4986
@highlightmatchoffootball4986 2 жыл бұрын
thank you so muchhh
@ayoubmazrou8800
@ayoubmazrou8800 4 жыл бұрын
I have a question , I don't know how to create a recyclerview of videos ? , I saw your implementation but it doesn't works in my own project
@Hereisthething
@Hereisthething 5 жыл бұрын
thanks for the video mitch and to clarify the retrofit cache is just in-memory right? i.e. if you kill the app and restart the app when you are offline, there is no cached data
@codingwithmitch
@codingwithmitch 5 жыл бұрын
It's saved to a file. It persists if the app dies I believe.
@rohitmandiwal8567
@rohitmandiwal8567 4 жыл бұрын
None of the solution worked for me.. but yours :)
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
we love you keep going.
@preenxus3425
@preenxus3425 5 жыл бұрын
This is the many helpful. Thanks a lot!
@eaglepaul
@eaglepaul 5 жыл бұрын
Thanks Mitch. Love u😍
@codingwithmitch
@codingwithmitch 5 жыл бұрын
😘
@luiferadventures
@luiferadventures 5 жыл бұрын
and what about Glide?
@ArjunSingh-qt5jn
@ArjunSingh-qt5jn 4 жыл бұрын
Thankx brother - Vancouver
@HabeshaDeveloper
@HabeshaDeveloper 5 жыл бұрын
please make firebase realtime database pagination
@salmanhameed9495
@salmanhameed9495 5 жыл бұрын
you didn't make serviceGenerator class' constructor private so, how it could be singleton ?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
You got me
@jawadahmed6190
@jawadahmed6190 5 жыл бұрын
Hi mitch how to use retrofit cache in this secenario? When we have internet save data in cache but dont use .But if we dont have internet we use cache .
@codingwithmitch
@codingwithmitch 5 жыл бұрын
That's what it does by default
@jawadahmed6190
@jawadahmed6190 5 жыл бұрын
@@codingwithmitch Oh thanks. I didn't know that.
@maherabuthraa8975
@maherabuthraa8975 3 жыл бұрын
You are right .. caching sucks .. mainly on server-side.. biggest pain is caching error . OMG
@chirantanchaudhury2809
@chirantanchaudhury2809 5 жыл бұрын
very useful video for developers
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
please make more application with rxjava. we learned but don't know where to use
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Makes sense. I will do some examples of where it's commonly used.
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
@@codingwithmitch thank you for your response
@codingwithmitch
@codingwithmitch 5 жыл бұрын
@@muraddadasov8595 maybe I'll do a video where I show you 5 of the most common ways to use it or something
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
@@codingwithmitch thank you lot
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
teacher should i go for both mvp and mvvm or only one?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Use one architecture per application IMO. But that is just my opinion. More than one would get confusing I think
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
@@codingwithmitch thank you much
@preenxus3425
@preenxus3425 5 жыл бұрын
You are dont use m-prefix?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I stopped doing that recently. Not for any particular reason.
@mohammedhamouda104
@mohammedhamouda104 4 жыл бұрын
love it
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
teacher. the thing that i didn't understand is maxStale. you assigned for 7 days. what happens after 7 days ?
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Here you go my friend stackoverflow.com/questions/33818854/what-is-difference-between-max-age-and-max-stale-in-cache-control-mechanism
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
please teacher make video about PageKeyedDataSource
@codingwithmitch
@codingwithmitch 5 жыл бұрын
Dunno what that is
@muraddadasov8595
@muraddadasov8595 5 жыл бұрын
@@codingwithmitch it is used with pageadapter
@enricobrunodelzotto7486
@enricobrunodelzotto7486 5 жыл бұрын
Setting a cache on the network layer it's ok, but what you're doing here is kind of an hack. Override headers with interceptors could be ok for a *fast* demo, but, all that part of logic should be done by the server. The caching at app level should be done with the repository pattern, in the higher level! So i really really no encourage people to follow the hack approach!
@codingwithmitch
@codingwithmitch 5 жыл бұрын
I said not to do this... This is how you should cache github.com/mitchtabian/Local-db-Cache-Retrofit-REST-API-MVVM
iOS Development is Easier than Android Development (VLOG)
20:41
CodingWithMitch
Рет қаралды 52 М.
MVVM  / MVI Repository Pattern with Hilt
1:00:24
CodingWithMitch
Рет қаралды 67 М.
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 10 МЛН
Magic trick 🪄😁
00:13
Andrey Grechka
Рет қаралды 42 МЛН
LiveData with Coroutines and Flow (Android Dev Summit '19)
18:44
Android Developers
Рет қаралды 110 М.
Advice from a Principal Software Engineer at Amazon (Steve Huynh)
22:45
Hilt makes testing easier on Android
32:38
CodingWithMitch
Рет қаралды 16 М.
MVVM and LiveData on Android
10:41
CodingWithMitch
Рет қаралды 36 М.
How This New Battery is Changing the Game
12:07
Undecided with Matt Ferrell
Рет қаралды 101 М.
Redis in 100 Seconds
2:26
Fireship
Рет қаралды 699 М.
DO NOT do this in a Software Engineering Interview
7:59
CodingWithMitch
Рет қаралды 9 М.