# PlayerData: refresh() method

> The refresh() method of the PlayerData interface drops what the room holds of the player's data, so the next get() reads it again.

The **`refresh()`** method of the [`PlayerData`](/docs/room/player-data) interface drops what the room's cache holds of the player's data, so the next [`get()`](/docs/room/player-data/get) of each key reads it from the data service.

## Syntax

```ts
refresh()
```

### Parameters

None.

### Return value

A `Promise` that resolves with `undefined` once the cache is dropped.

## Description

Without `refresh()`, a write made outside the room, by a client, another room or your backend, shows in the room's `get()` within 5 seconds. Call it when the room knows such a write happened and needs it at once.

## Examples

### Reading a purchase the shop just made

The client buys through your backend, then tells the room.

```ts
// purchases.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onMessage(room, connection, message) {
    if (message !== "bought") return;
    const data = room.playerData(connection.player);
    await data.refresh();
    const gems = await data.get<number>("gems");
    room.send(connection, { type: "gems", gems: gems?.value ?? 0 });
  },
});
```

## See also

- [The cache in the room](/docs/room/guides/player-data#the-cache-in-the-room)
