Cache Eloquent Query Results to Load Pages Instantly

  Рет қаралды 60,935

Laravel Daily

Laravel Daily

Күн бұрын

Пікірлер: 77
@alexeykhachatryan1214
@alexeykhachatryan1214 4 жыл бұрын
With DB we have two actions - ADD and GET (INSERT and SELECT) In case if it's GET - get from cache. In case if it's ADD - add in DB, and fire an event to update the cache. You could talk about this method in your video. Great job!
@stefanbogdanovic590
@stefanbogdanovic590 4 жыл бұрын
Awesome idea! Or just invalidate the cache after inserting new entity. But I think your idea is better :)
@impulserr
@impulserr 4 жыл бұрын
Great idea so you don't need to care about how long to store, you can set forever and just update ;)
@eboubaker3722
@eboubaker3722 3 жыл бұрын
You just answered the question I asked in my head after watching the video, this is an effective and brilliant technique.
@VictorSBFI
@VictorSBFI 2 жыл бұрын
An Observer should do that work.
@alexeykhachatryan1214
@alexeykhachatryan1214 2 жыл бұрын
@@VictorSBFI should or can do that?
@paulfontaine7819
@paulfontaine7819 3 жыл бұрын
In case you want the cache to refresh every day, first call after midnight, just add the day in the cache key string. The key then changes every calender day. The old values will be cleared from the cache based on the provided timeout.
@robiparvez
@robiparvez 4 жыл бұрын
regarding database update issue, you can just add a check, where you can assign the cache value to a variable and add empty check. If empty, query from db else load the cache.
@Frank-ou2nr
@Frank-ou2nr 4 жыл бұрын
He was talking about the use-case where your cache does have data inside of it, but in the meantime your database was updated and the (now old) cache data is still stored in the file. Using what you suggest (checking if the cache has value) will not work in this case; the cache is not empty and thus your query will never execute and the old data will still be used by your application.
@oleoni1437
@oleoni1437 4 жыл бұрын
@@Frank-ou2nr what you mentioned is correct so one way to avoid that it would be to clear the cache every time the data get updated
@MrAhmedUA
@MrAhmedUA 4 жыл бұрын
@@oleoni1437 yeah with some drivers which support cache tags you can for example if you have a cron that gets data from api daily you can do something like Cache::tags(['live-system'])->flush(); also maybe with laravel Eloquent Model upadating ~ deleting ~ creating events you can flush the cache too
@howtotech3956
@howtotech3956 4 жыл бұрын
321 likes and 0 dislikes. thats what called a quality channel.
@alnahian2003
@alnahian2003 Жыл бұрын
This video is sooo interesting that I frequently comeback rewatch it.
@videomania1635
@videomania1635 3 жыл бұрын
your each and every video is great source of learning. Thanks...
@Shez-dc3fn
@Shez-dc3fn 4 жыл бұрын
the thing with caching i find is then i have to make sure that the cache is deleted on update or w/e... this can get messy if you have lots of cache for different things.. cache packages help but no package afaik has solved the problem of caching relation and then deleting them if relation data changes..
@educat693
@educat693 3 жыл бұрын
I think we can use eloquent model events to clear the related cache. It will be a one time effort for each of the model, after that it will be peaceful life. What is your opinion on that? Please let me know.
@apairca
@apairca 4 жыл бұрын
I think it's much better and recommended to use a Carbon instance instead of seconds for cache time to live.
@doremidon
@doremidon 3 жыл бұрын
Why? Do you can explain?
@Maniac-007
@Maniac-007 11 ай бұрын
@@doremidonreadability
@alexrusin
@alexrusin 4 жыл бұрын
Nice video. What if a query runs not 1 second, but 10 seconds. Every day there will be a user that will have to take it for the team. That person may not be very happy. Any cache warming strategies?
@PovilasKorop
@PovilasKorop 4 жыл бұрын
Hmm, good point. What about artisan command which runs once per night and refreshes the cache in the background? So no actual user would feel that 10 seconds.
@devanggandhi3266
@devanggandhi3266 3 жыл бұрын
Hello Sir, I need your suggestion. I am mainly working on API. so is it good to use cache in every api to speed up response ? what are the cons of using the cache ? if my data will update after 2 hours then can it handel it means does cache give the updated data also ?
@muhammadfatur8415
@muhammadfatur8415 4 жыл бұрын
Very helpfull for me as begineer, thank's sir
@eid9552
@eid9552 4 жыл бұрын
Thank you for your nice tips. I have a question. What if the database is updated before the cache expires? Is there a way you suggest to get the latest data without loosing the performance?
@jesteriruka4215
@jesteriruka4215 3 жыл бұрын
You can run that query in parallel using crontab and artisan commands.
@НиколайШироков-т7л
@НиколайШироков-т7л 4 жыл бұрын
Thank you for your effort!
@RpExclusive
@RpExclusive 3 жыл бұрын
may i know what is the browser extensions you used ?
@WireDroid
@WireDroid 3 жыл бұрын
Laravel debugbar
@ChangeYourLifeForever
@ChangeYourLifeForever Жыл бұрын
THANK YOU GODFATHER
@ilmammourtada4538
@ilmammourtada4538 4 жыл бұрын
Thank you for the video. May I ask what is that console you are using to show the query?
@PovilasKorop
@PovilasKorop 4 жыл бұрын
Laravel Debugbar, if that's what you meant by "console".
@santysasa12
@santysasa12 2 жыл бұрын
Awesome tip! Thanks a lot
@ihtishamahmad65
@ihtishamahmad65 2 жыл бұрын
Where does this cache save? in Browser or our Laravel Application?
@lifestyleblog6318
@lifestyleblog6318 2 жыл бұрын
Did you used any extension for checking the Queries
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Laravel Debugbar
@Lightnings123
@Lightnings123 3 жыл бұрын
is it possible to cache on a resource::collection with pagination?
@oscarfelipeporras9973
@oscarfelipeporras9973 4 жыл бұрын
amazing as always
@namazbekbekarysuly9112
@namazbekbekarysuly9112 4 жыл бұрын
It is great video. Let's say one applications needs to cache queries in multiple places. How can we regularly trigger caching in all places at particular time. Should we make a cron job that runs some command CacheApplicationCommand?
@Netherlands031
@Netherlands031 4 жыл бұрын
I think you can indeed make a laravel scheduled task to your custom command, that uses Cache::put to make sure there's always a fresh cache and users never have to hit the db (for some queries), and then run that command as well when something in the db gets updated and you need to refresh the cache
@lukmanulhakim8841
@lukmanulhakim8841 3 жыл бұрын
Are it's save for used on production sir?
@amitleuva8739
@amitleuva8739 2 жыл бұрын
can a query be cached using redis?
@javerleo
@javerleo 2 жыл бұрын
Excellent explanation! Thanks. Does it work with Eloquent models in Livewire components?
@LaravelDaily
@LaravelDaily 2 жыл бұрын
Yes, same
@lifestyleblog6318
@lifestyleblog6318 2 жыл бұрын
can i used file cached in laravel ?
@MzN...
@MzN... 3 ай бұрын
Thx
@tienphungkhac1491
@tienphungkhac1491 Жыл бұрын
What is the extension you just using in the browser?
@LaravelDaily
@LaravelDaily Жыл бұрын
composer require barryvdh/laravel-debugbar
@tienphungkhac1491
@tienphungkhac1491 Жыл бұрын
@@LaravelDaily thanks
@danorex9100
@danorex9100 4 жыл бұрын
Thank you for video :)
@mreduar
@mreduar 4 жыл бұрын
I have a website that updates the database every time the user downloads a document, that is, I keep track of the downloads of that document. When the database is updated, the cache is lost in the whole app only because of that number update. Any suggestion for this situation?
@PovilasKorop
@PovilasKorop 4 жыл бұрын
You're probably caching the wrong thing, then. Instead of having one cache query for the whole app, maybe you should cache some specific things that wouldn't be re-cached after one number update. Or, maybe, you should be ok with holding the cache for a little more and not refresh it after EVERY download, just maybe once per hour or so.
@santiagotv6095
@santiagotv6095 3 жыл бұрын
@Laravel Daily what is the extension yo used to view the query, timeline and etc. like 0:20
@WireDroid
@WireDroid 3 жыл бұрын
Laravel debugbar
@anasbousrateh9537
@anasbousrateh9537 4 жыл бұрын
Thank you for this amazing video, it's really helpful
@music-masala-7789
@music-masala-7789 3 жыл бұрын
if we have dynamic user Id and other field is user IP , this cache is usefull or not ?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
You need to measure it.
@EugeneChe-81
@EugeneChe-81 4 жыл бұрын
Круто) Спасибо)
@fire23hummer
@fire23hummer Жыл бұрын
Perfectooo :)
@ricko13
@ricko13 3 жыл бұрын
This is an excelent feature if you know how and when to use it, I did it wrong and I receive an email from my server provider telling me that my VPS reached a high I/O and so a shutdown was required It was triggered cuz I was using the "file" cache driver in Laravel #LessonLearned
@fahrim2729
@fahrim2729 4 жыл бұрын
Best sir
@shuvoahmed5217
@shuvoahmed5217 3 жыл бұрын
Make a video about laravel horizon with php redis. Its not working on windows
@kid_rz
@kid_rz 4 жыл бұрын
what aboout paginate data?
@mudzarao
@mudzarao 3 жыл бұрын
Same question. Have you tried playing around it? If yes, did you manage to find a solution for it?
@DanZL1
@DanZL1 4 жыл бұрын
Thank you for the great videos you make. Since you are knowledgeable on Laravel, perhaps you can share your perspective on the following. While speaking to a developer about Laravel and converting our WP website to Laravel, their reply was that Laravel is still unstable and has releases every months or so. What's your response to this?
@PovilasKorop
@PovilasKorop 4 жыл бұрын
I already replied to you, on another video, read the comment here: kzbin.info/www/bejne/qXLNfYV7gtdgb80&lc=UgxfpVnVL60BIdxtnd54AaABAg
@SKIDKOVOZ
@SKIDKOVOZ 2 жыл бұрын
Hi I am from Ukraine. I have a problem, I make link shortener on laravel - with counter by clicks on short link, and i have a trouble with add link to cashe and counter clicks on it - correctly, may I ask about some lesson from you about this, or maybe paid lessons so that you help me learn how to do what I want? I am not programmer i try make some functions for myself.
@DBRSAstonMartin
@DBRSAstonMartin 2 жыл бұрын
How would you refresh the cache say that book title was updated in the database?
@raminjavi161
@raminjavi161 2 жыл бұрын
You are such a perfect teacher. I love the way you teach; Your lessons are short, real, and useful. Thank you
@gado_official
@gado_official 4 жыл бұрын
I wonder if using pagination is it method would works or not?
@khizer3528
@khizer3528 2 жыл бұрын
Thanks for the useful information .
@isaaclovera8975
@isaaclovera8975 3 жыл бұрын
How to the cache in LiteSpeed?
@mohidden
@mohidden 4 жыл бұрын
best of the best laravel tutos.sup of laravel thanks sir.
@HosamHasanMonir
@HosamHasanMonir 4 жыл бұрын
Very helpful , Thanks a lot.
@mukhtorov
@mukhtorov 4 жыл бұрын
Thanks!!
@adriannvalera9923
@adriannvalera9923 4 жыл бұрын
Hi sir. May I know what database you use?
@PovilasKorop
@PovilasKorop 4 жыл бұрын
MySQL
Faster Eloquent: Avoid Accessors with Foreach
9:35
Laravel Daily
Рет қаралды 53 М.
БЕЛКА СЬЕЛА КОТЕНКА?#cat
00:13
Лайки Like
Рет қаралды 2,1 МЛН
Ozoda - Lada (Official Music Video)
06:07
Ozoda
Рет қаралды 11 МЛН
Why Don't We Have A Laravel For JavaScript?
12:36
Theo - t3․gg
Рет қаралды 104 М.
Laravel Eloquent: Deeper Relationships with One Query
10:37
Laravel Daily
Рет қаралды 141 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 360 М.
Laravel: Create Public API with Cache and Rate Limits
12:18
Laravel Daily
Рет қаралды 46 М.
Laravel Security: Top 7 Mistakes Developers Make
11:16
Laravel Daily
Рет қаралды 84 М.
Laravel + Livewire todo app (and so much more)
16:41
Aaron Francis
Рет қаралды 45 М.
Optimizing Eloquent: Running Out Of Memory?
6:11
Laravel Daily
Рет қаралды 43 М.
Caching | Laravel 10 Tutorial #46
16:37
Yelo Code
Рет қаралды 3,6 М.
[Live-Coding] Refactor Laravel Controller to be Much Shorter
14:55
Laravel Daily
Рет қаралды 77 М.
The secret behind FrankenPHP: Will it revolutionize PHP?
12:40
Chris Fidao
Рет қаралды 41 М.
🥹❤️
0:40
Софья Земляная
Рет қаралды 3 МЛН
Incredible: Teacher builds airplane to teach kids behavior! #shorts
0:32
Fabiosa Stories
Рет қаралды 10 МЛН
Моноколёсник едет 100 в городе!
0:44
FastMotion
Рет қаралды 8 МЛН