Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dreamer's avatar

The right way to cache dynamic content

Hello

I am unsure how this is best handled by experienced developers. I have a page that has a lot of dynamic content in it. Some content comes from ajax, another is set/created by jquery.

Now, how can i make it so when user clicks reload or clicks on a link and then comes back to a page, the page would still look like it was with all the dynamic content.

I know it is made by Laravels Cache: http://laravel.com/docs/5.2/cache

But, how to best implement it for views with dynamic content. Do i have to make an ajax that saves view to cache every time something changes? Or i have to ajax cache everything separately?

For example, if client is selected, do i have to put 'client' into cache and then check for it in the view and if exists, display it? Or i can just update view cache of the whole page?

Any tips would be appreciated!

0 likes
5 replies
SachinAgarwal's avatar

@Dreamer What you can do is, create a cache forever. And reset it when new content is added to the database. That is in the Model's created event just forget the previous cache and recreate it.

Dreamer's avatar

@SachinAgarwal Thanks, im not actually talking about db cache. Im going to do most caching as part of a last optimization before uploading the page. What i am after is caching part of a page. It may not be related to any model or data from db. It can be something as simple as dynamic empty div, or something as complex as list of items retrieved with ajax that are somehow modified by user dynamically.

I want all changes that user does take effect when user clicks save button. Not when user tinkers with data. And i want so that user would not lose any changes when they accidentally click a link or something.

Dreamer's avatar

Thanks, ill theck both of these out :)

Please or to participate in this conversation.