Caching Your API Requests (JSON) In Python Is A Major Optimization

  Рет қаралды 18,548

Indently

Indently

Күн бұрын

Пікірлер: 18
@julianunes2124
@julianunes2124 2 жыл бұрын
Hey there, this video helped me a lot today. Thanks! :)
@20SideDieTriva
@20SideDieTriva Жыл бұрын
have yiu tried pythons requests_cache? it's very robust
@Indently
@Indently Жыл бұрын
Not at all, thanks for the recommendation, I'll check it out!
@silkogelman
@silkogelman Жыл бұрын
@@Indently requests_cache is really awesome. You'll probably almost never apply the method in your video again as with requests_cache your caching system is easier to implement, maintain and has lots of ways to be configured. (and applied: valuable for testing and production environments) I used to do it the way you show in your video too, but with requests_cache I never looked back. It has great documentation, but there's no detailed video about it yet. So there may be an opportunity for your KZbin channel there.
@pietart3596
@pietart3596 Жыл бұрын
@@silkogelman I agree using requests libraries for production environment is very beneficial. For personal projects Indently's method is easier and more optimised. We aren't depending on an entire third party library
@starogre
@starogre Жыл бұрын
what data wouldnt change from json exactly? maybe like news articles? or something that never gets updated? any other examples? movie names?
@EnzoSantos
@EnzoSantos Жыл бұрын
Basically, something that changes once in a blue moon. For example, I was using the ytmusicapi in Python these days, which returns metadata about songs, albums, and playlists from KZbin Music. I know it's very unlikely the "The Dark Side of The Moon" album to change their duration or song order between one request and another, so we can cache it. Another example is a Wikipedia page from a dead person or the script of a movie.
@saifshaikh5559
@saifshaikh5559 4 ай бұрын
Why I am not able cached google maps api requests?
@ricgondo
@ricgondo Жыл бұрын
Wow, I wish I knew this some time ago. Cool!
@borutouzumaki2120
@borutouzumaki2120 2 жыл бұрын
Hi this tutorial really help, but can we set the cache to be expired after 30minutes or an hours?
@Indently
@Indently 2 жыл бұрын
Of course!
@borutouzumaki2120
@borutouzumaki2120 2 жыл бұрын
Could uh please tell me how to do that? Because um still new in python
@swagatopablo
@swagatopablo Жыл бұрын
@@borutouzumaki2120 Not to rain on the parade here, and it is always commendable when people share educational stuffs to benefit the community. That said... It is not a great design choice to cache on your disk, that too with plain text. That not only makes the server stateful, it can even be slower than the network (if you are making request from on-prem network). But regardless, the video explains the concept and implementation of caching quite well. To answer your question directly, if you are to follow this, whenever you write the json, along with the relevant api response, you can add an 'expires' key to indicate when it will expire. Can set it 30 minutes (or any time) from the write timestamp, you can use the unix epoch as the simplest representation of a time instant here to serve the purpose. Look up python pendulum library for time operations. At read time, if the current epoch is higher than expires, then you should refresh the json. But a far better choice is to use some service like Redis for caching. (You need do a bit of your research on how to use it.) You can also set up redis keys to self destroy after some time for cache eviction.
@Sameer_Pattnaik
@Sameer_Pattnaik 5 ай бұрын
It doesn't work from my side
@disrael2101
@disrael2101 2 жыл бұрын
Any automation bootcamp/course coming up?
@BroganMcShane-h1k
@BroganMcShane-h1k Жыл бұрын
The structure of your code could be improved, it doesn't read well
@Indently
@Indently Жыл бұрын
Noted
@florinbujoreanu1020
@florinbujoreanu1020 10 ай бұрын
I think he joked.. He can't be serious. @@Indently
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 110 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,3 МЛН
Don't Keep Requesting API Data, DO THIS!
9:52
John Watson Rooney
Рет қаралды 12 М.
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 820 М.
Working With APIs in Python - Pagination and Data Extraction
22:36
John Watson Rooney
Рет қаралды 112 М.
React's new cache function
10:14
Ryan Toronto
Рет қаралды 11 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
You Don't Need Try/Catch Anymore With This New Operator
16:08
This is why you need caching
10:03
Web Dev Cody
Рет қаралды 48 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН