Nice video. Just also want to mention that if you were to follow such a pattern, be aware that you need to check for outdated data, especially if you're working with data that changes a lot. One way to do that is to also attach a Date object to that specific data you're pulling in, and add some time limit for how long something will be stored in the proxy - which will be checked every time you try to fetch something via it. If you want to do a lot of this, it's worth checking out Redis, a cache database.
@DevSage5 жыл бұрын
Thanks for the tip!
@sbr43393 жыл бұрын
@@DevSage Yeah those prices definitely seem to be outdated by now
@CottidaeSEA2 жыл бұрын
It's easy enough to just clear it with setTimeout. Let it be cached for 10 minutes or something like that. if (cache[key] === undefined) { cache[key] = fetchFromApi(); setTimeout(function() { cache[key] = undefined; }, 10 * 60 * 1000); // 600000 ms but easier to read just for the sake of the example. } return cache[key];
@georgegolovchiner6575 ай бұрын
Hash comparison between proxy and the original object is required. So there should be at least one network call to the original to verify cache validity.
@neuodev2 жыл бұрын
this video is my "Proxy" for Design Patterns!
@GopalSinghR14 жыл бұрын
Thanks man this is crystal clear explanation
@TheArmanist11 ай бұрын
Looks like more as singleton pattern..
@zikrilariliusra47374 жыл бұрын
Nice and clear explanation. i hope your channel will grow up like thenewboston and traversymedia
@DevSage4 жыл бұрын
I appreciate it
@js_programmer84232 жыл бұрын
can you actaully use this example in the real world or would i need to set up a real cache? like setting up cookies? or is cache basically a proxy pattern itself?
@DevSage2 жыл бұрын
Really depends on what your application needs to do. Having the cache built in the code here is obviously just for example purposes, but if you had a real life web application that lived on a real server, yeah you probably would need to implement the cache in a different way (like using a Redis instance as the proxy, or using browser cookies etc). The cache is more just the idea, how you implement it is completely up to you.
@js_programmer84232 жыл бұрын
@@DevSage got it, thanks !
@theotherme99653 жыл бұрын
Is this the pattern used for service workers?
@DevSage3 жыл бұрын
Yes. Good observation
@pawandeore1656 Жыл бұрын
but now don't we have the problem of stale data? how to deal with that
@kirillpavlovskii83423 жыл бұрын
great, I like this teaching style , it would be nice to do patterns on TS
@vasurangpariya84922 жыл бұрын
I have question that we can also impliment features in main function then why we need proxy pattern
@mahdiali4299 Жыл бұрын
Thank you very much, but you haven't used Proxy keyword in the code. This is Proxy pattern or memoization pattern?
@hadibohluli52072 жыл бұрын
by far best explain for design patterns , I appreciate it, please make Adapter pattern video
@satlibwanzai1114 жыл бұрын
Thank you Sage. But why would you declare cache as an object, then use it as an Array? Why don't you declare cache as an array in the first place?
@DevSage4 жыл бұрын
I'm not using it as an array. The 'cache[coin]' syntax is an ES6 feature known as 'computed property'. 'obj' is an object and 'coin' is a variable. Javascript automatically uses the value of the variable and creates a new property on 'obj' with the value of that variable. Example const obj = {} const coin = 'bitcoin' obj[coin] = 'hello' // this is the same thing as obj.bitcoin = 'hello'
@TimWinfred3 жыл бұрын
Awesome video! Thank you!!!
@DevSage3 жыл бұрын
You're welcome! 🤙
@clingyking2774 Жыл бұрын
I think this is also reffered to as facade pattern
@tommyshaw24205 жыл бұрын
but wait im confused....If you cashe the value, then the value will not update? so when the value changes on the other end you wont know?
@DevSage5 жыл бұрын
You are correct. This example could be modified in a way that cached values store a timestamp as well as the coin data. Whenever you call the proxy, check to see if the timestamp of the previous call is 'too old'. If it's old, call the API and store the new value.
@johnsonye71244 жыл бұрын
@@DevSage what if handling real time data? If set timestamp for the cache, it still not going to get the data update in real time. How can we use observer pattern to handle real time data?
@developerAKX4 жыл бұрын
Love form India bro
@developerAKX4 жыл бұрын
Thinks bro
@unicrix5 жыл бұрын
I wanna know about ES6 proxy instead of this. But thanks for making this video, this is a nice design pattern.
@georgegolovchiner6575 ай бұрын
ES6 adds syntactical sugar, however it's useful to know the basics first, so this video is still very useful for a novice
@raymondmichael49875 жыл бұрын
Dude you're doing such a great work bro. But can adjust that theme, it's too dark. Otherwise I learned a lot. Greetings from Tanzania 🇹🇿
@DevSage5 жыл бұрын
Thank you
@be2wa2 жыл бұрын
What's too dark? The contrast is OK, so it's readable and it doesn't tire your eyes like the white theme. If anything is too dark then it's probably your monitor