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

sr57's avatar
Level 39

Cache clear in production?

Any risk to do php artisan cache:clear in production?

Some user's troubles are not a risk for me if data cannot be lost/damaged.

1 like
10 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@sr57 As of my understanding, the is no risk to delete your data once run the cache:clear. You can do it.

6 likes
sr57's avatar
Level 39

Thanks, wait to see if other comment(s) before select best answer.

5 likes
Tray2's avatar

The only affect it will have is that the first request will take a tiny bit longer.

7 likes
sr57's avatar
Level 39

Thanks, normal and not a risk.

4 likes
MichalOravec's avatar

Cache your data for a few hours, it means don't use rememberForever.

For example

$users = Cache::remember('users', now()->addHours(12), function () {
    return User::all();
});

For next 12 hours it doesn't touch data from a database. After that time it will be again retireved from the database a cached.

Docs: https://laravel.com/docs/8.x/cache#retrieve-store

When your run php artisan cache:clear it just remove all cached data, but they will be again retrieved and cached from database. It's normal when want to refresh all data on your app at the same time.

2 likes
sr57's avatar
Level 39

Thanks for your reply.

For next 12 hours it doesn't touch data from a database.

Ok, can be useful sometimes, I have to test later.

No possibility to select the period, let's say for instance to transfer to/from the db only during the night?

2 likes
MichalOravec's avatar

It doesn't matter. Who first visit your page then it will be cached for the next 12 hours in this case.

It could be 5 minutes. It's up to you.

now()->addMinutes(5)
2 likes
sr57's avatar
Level 39

Thanks I did not understand it's per user.

2 likes
sr57's avatar
Level 39

THANKS, I have to test to better understand ... later.

1 like

Please or to participate in this conversation.