Chapters
25 Chapters
|
2:34:05
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.1",
"ext-ctype": "*",
"ext-iconv": "*",
"knplabs/knp-time-bundle": "^1.18", // v1.19.0
"symfony/asset": "6.1.*", // v6.1.0-RC1
"symfony/console": "6.1.*", // v6.1.0-RC1
"symfony/dotenv": "6.1.*", // v6.1.0-RC1
"symfony/flex": "^2", // v2.4.5
"symfony/framework-bundle": "6.1.*", // v6.1.0-RC1
"symfony/http-client": "6.1.*", // v6.1.0-RC1
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/runtime": "6.4.3", // v6.4.3
"symfony/twig-bundle": "6.1.*", // v6.1.0-RC1
"symfony/ux-turbo": "^2.0", // v2.1.1
"symfony/webpack-encore-bundle": "^1.13", // v1.14.1
"symfony/yaml": "6.1.*", // v6.1.0-RC1
"twig/extra-bundle": "^2.12|^3.0", // v3.4.0
"twig/twig": "^2.12|^3.0" // v3.4.0
},
"require-dev": {
"symfony/debug-bundle": "6.1.*", // v6.1.0-RC1
"symfony/maker-bundle": "^1.41", // v1.42.0
"symfony/stopwatch": "6.1.*", // v6.1.0-RC1
"symfony/web-profiler-bundle": "6.1.*" // v6.1.0-RC1
}
}
26 Comments
In Symfony 6.1 new class' name is
Symfony\Contracts\Cache\ItemInterfaceso you have to change callback like this:function(ItemInterface $cacheItem) {}Cheers
Danilo
Hey @Fedale!
Thanks for the note! In truth, both work just fine in any Symfony version, though I probably should have used
ItemInterface.ItemInterfaceextends theCacheItemInterfacethat we use in this video, so both work. However, if you useItemInterface, then you have addition->tag()and->getMetadata()methods to give you more flexibility.Cheers!
could be the reason why it ever reads from API and never from cache?
Yo @FooBacke!
That would definitely disable caching in the
devenvironment (well, if you called the same method 2 times in the same request, it would fetch from the cache the 2nd time... but not really true caching). But where did you see this config? Is it something you added in your app - or did we add it in the screencast (I couldn't find us adding this - but I may be forgetting).Cheers!
I'm trying to invalidate the first mixed_data chached item without ttl but it's not working.
I tried with:
If I test again with private browser and let the npm run watch running, I always still hitting the cached item.
If I change the cache name to a new one it works.
The only thing that changes if I clear the cache.app is that the total cache calls are increased from 1 to 3 in that request (100% hits/reads).
Do you use symfony docker? Then you need to run it as
docker-compose exec php bin/consoleHey @droptica_team ,
Thanks for this tip! Yeah, either run the bin/console from inside the container, or leverage Symfony binary, i.e. run it via
symfony consoleand Symfony will handle Docker stuff for you.Cheers!
Yes, I forgot to mention that I was using docker, but it makes sense and I'm pretty sure that it's about that. Thanks @droptica_team
Hey ZidK,
OK great, then @droptica_team tip should help, or for simplicity just call any console command via Symfony binary,, e.g.
symfony console- and it will be handle Docker setup for you automatically.Cheers!
Hey @ZidK!
Hmmm, that is super weird. It's especially weird that passing
--allwould STILL not result in the item being cleared... as that is supposed to clear ALL the cache pools. In this tutorial, thecache:pool:cleardefinitely seemed to work for me... I'm really not sure what would be going on in your case. Are you using the filesystem adapter like we are - or something else?Cheers!
I don't know how fix this error
Hey @Xavi
You imported the wrong interface, this is the one you should be using
Symfony\Contracts\Cache\CacheInterface;Cheers!
Oh my god...
Thank you so much!
My Httpclient is working but it not appearing in the profiler. Can you please let me know what I am doing wrong
My Http Client didn't appear as well in the profiler. When I find out, I had to update the Symfony version from 6.1 to 6.3. After upgrading, I can see the Http Client in the profiler. Maybe there was a bug in Symfony 6.1 regarding the Http Client in the profiler.
Hey @mahesame ,
Thanks for this tip!
Cheers!
Hey BossManF,
If you do any redirects after the API request with HTTP client sent - you won't see those in your profiler for the latest request. You will need to find the specific app request where you you send those API requests with HTTP client in the Last 10 requests first.
Cheers!
A question about cache expiration: do we need to call the expiresAfter(5) function if the cache lifetime is already configured to 5 second like this cache.pool.default.default_lifetime: 5
I mean, does default_lifetime do the same job of expiresAfter function ?
Hey @ahmedbhs
Yes, that's how it is supposed to work. The default lifetime value will be added up to the time when the cache item was created
Cheers!
Does the
php bin/console cache:pool:clear cache.appcommand the same as thephp bin/console cache:clearcommand?Hey @Vlame!
Excellent question! These are actually 2 different things for the 2 different types of cache in Symfony
A)
cache:pool:clearis used to clear the "cache" that we were talking about in this tutorial. This is the cache where you can store items, including things for your application but also the core stores some things in cache pools. For example, Doctrine caches the DQL -> SQL generation in a cache pool. In short, when you think about a "caching system", this command is used to clear those.B)
cache:clearhas a different purpose. When Symfony loads, internally, it caches a bunch of stuff - most importantly it caches your routes after parsing them and it caches all of your services. This is all stored in thevar/cache/devdirectory (orvar/cache/prodin theprodenvironment) and it's not something you typically need to think about. If a routing file changes, Symfony automatically rebuilds this cache. These are fundamental cache file that Symfony needs to even function.You'll run
cache:cleareach time you deploy, because you DO want to rebuild these cache files (these cache files are 100% built from your code - so if your code changes, you should rebuild the cache). But you'll rarely runcache:pool:clearas these are typically things that you want to keep in cache until they expire.Let me know if that helps!
Cheers!
Hello @weaverryan,
Thanks for your answer! It is clear for me what the differences are. Thanks a lot!
Would there be a possibility to process some new examples of creating services and bundles in future lessons? For God's sake, since version Symfony 3 you have been demonstrating examples with the Cache and MarkDown helper - service.Are there any other examples besides those?
Hey Vlada,
We have a separate course about creating a Symfony bundle, I think you might be interested in it, you can check it out here: https://symfonycasts.com/sc...
Hm, the idea of this course is not about learning how write an implementation of a specific service, but how to write service in general. We cover everything you need to be able to create *any* service and inject any dependencies into them. But I see your point, we will try to find a different service example in future tutorials just to diversify out tutorials for those who are watching past courses as well. Thank you for you feedback! Also, if you have any ideas what specific services would be great to cover in your opinion - please, share it!
Cheers!
I respect your work and the effort you put into creating new lessons, but I believe that there must be something new because sticking to old lessons and changing only the version of the Symphony does not contribute to the quality of learning and mastering the material. If the Symphony team claims that the Symphony is so powerful (I honestly believe that this is true) then demonstrate that strength and power through various examples and not through just one example. I'm not a lecturer, nor do I consider myself an excessively experienced programmer, but if you're already asking me to suggest specific examples for bundles and services, then you could, for example, in with your lessons, you show how to make a specific visual web control that could be used as a package in various web applications. For example, a DataGrid control with the implementation of data pagination, filtering and sorting data or DataView control as they exist in Yii2 framework. The KnpPaginatorBundle package almost always has some bugs and does not work in new versions of Symfony. The EasyAdmin bundle is too crowded with functions for simple display of data in a DataGrid with elementary possibilities that these controls should offer (pagination, sorting and filtering and nothing more ... ). An even better example would be the implementation of a separate layer of the database with business rules (n-tier web application) as a separate service.
Greeting.
Hey @Влада Петковић
Yea, sorry for the repetition. These "basic" courses aren't really meant to be different across Symfony versions... we just give them an "update" do keep the content current. If you're watching them across Symfony versions, you're definitely going to hear the same things over and over again :). What I need to do (and it's my goal for the summer) is to quickly finish these basic course updates so we can get into bigger and better things.
> For example, a DataGrid control with the implementation of data pagination, filtering and sorting data
That's a cool idea... and I've been liking the idea more lately of having some shorter tutorials that just solve some interesting problem vs teach a concept in Symfony (we will still have those, but just "coding up a feature" I think is an interesting idea).
Anyways, thank for the idea and patience - I realize that these "basic" Symfony tutorials are not much fun for seasoned Symfony devs :).
Cheers!
"Houston: no signs of life"
Start the conversation!