laracasts / Lets-Build-a-Forum-in-Laravel

http://laracasts.com/series/lets-build-a-forum-with-laravel
914 stars 311 forks source link

Fixing an issue with Channels shared variable #30

Open rsm23 opened 7 years ago

rsm23 commented 7 years ago

Since we are storing the channel variable as a cache for ever, the first batch of channel(s) will be stored and whenever we change, remove or add a channel the channels variable is never been updated. What I did here is to clear the chached whenever the model is, updated, created, or deleted, to create a new batch of channels.

Maybe you'll find a better implementation for that, but I think something like that is mandatory, when the development is finished.

I was thinking to use this on the AppServiceProvider but the whole thing about performance will be for nothing, since this will be called every time the application boots or every time a view is called.

rsm23 commented 7 years ago

@JeffreyWay @laracasts Still waiting your response. Best Regards

nathanheffley commented 6 years ago

I can't seem to find exactly where he mentions it, but this was intentional. He said that a list of Channels isn't likely to change very often, so he doesn't mind manually busting the cache.

Because of that, I highly doubt he is going to add an automated system for doing it.

rsm23 commented 6 years ago

Yeh but this PR will only bust the cache just whenever a new channel ia created otherwise it's going to stay the same ;)

Thyrosis commented 6 years ago

Aren't you better off just doing a Cache::forget(channels'); though? Because if you use any other caching variables (like the one we use for the 'find new posts' functionality), with Artisan clear:cache you'll be clearing all of the cached variables, not just the channels.