# Cache a prop and forget it on write

> Cache::remember stores a public count. Forget that key when a post is created. Do not cache one user's drafts under a global key.

- URL: https://laravel-vuejs.space/laravel-cache-remember-vue
- Author: Anass Ez-zouaine (https://laravel-vuejs.space/author/anass-ez-zouaine)
- Published: 2026-10-11
- Topics: Laravel, VueJs

People searching “Laravel cache Vue page” remember the whole post list, including drafts, under one key. The next visitor sees the first visitor’s rows. Cache a public number. The page that shows private rows stays on the [CRUD guide](https://laravel-vuejs.space/laravel-inertia-vue-crud) query.

> **TL;DR**
>
> -   Cache::remember stores a public count.
> -   Forget that key when a post is created.
> -   Do not cache one user’s drafts under a global key.
> -   Do not `Cache::remember` a paginator that called `where('user_id', auth()->id())` under a key with no user id in it.
>
> **Who it's for:** Laravel + Vue developers
>
> **Applies to:** Laravel 13 · Vue 3

## The fix

```php
$stats = Cache::remember('stats.posts', now()->addMinutes(5), function () {
    return ['count' => Post::query()->count()];
});
```

Pass `$stats` as a prop. When a post is created or deleted, forget the key in that same request:

```php
Post::create([...]);
Cache::forget('stats.posts');
```

Five minutes is a choice for a homepage count, not for an editor.

## What to avoid

> **Gotcha**
>
> Do not `Cache::remember` a paginator that called `where('user_id', auth()->id())` under a key with no user id in it. Do not cache the rendered Inertia page in a way that includes the CSRF token. That token belongs to one session.

## FAQ

**Q: How do I cache a prop and forget it on write?**

Cache::remember stores a public count. Forget that key when a post is created. Do not cache one user's drafts under a global key.

**Q: What goes wrong with Laravel cache Vue page?**

Many developers remember the whole post list, including drafts, under one key. Do not `Cache::remember` a paginator that called `where('user_id', auth()->id())` under a key with no user id in it.
