> For the complete documentation index, see [llms.txt](https://docs.overdare.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.overdare.com/development/api-reference/classes/memorystorehashmap.md).

# MemoryStoreHashMap

MemoryStoreHashMap : `Instance`

## Overview

MemoryStoreHashMap is a key-value memory store shared by multiple servers in the same world. Use it to save and retrieve, by key, data whose latest state must be exchanged quickly between servers.

It can only be retrieved through the MemoryStoreService:GetHashMap() method and cannot be created with Instance.new().

This object can only be used in server Scripts, and calling it from a LocalScript raises an error.

**Storage Rules**

* Keys must be strings of 1 to 128 characters.
* Values must be 1 to 32,768 bytes when serialized. Saving a table with circular references or a value of a type that cannot be stored raises an error.
* Every item has an expiration time (in seconds), specified in the range of 0 to 3,888,000 seconds (45 days). Expired items are treated the same as items that do not exist.

**Important Notes**

* Because the storage is volatile, data may be lost when the storage restarts.
* Caching is not used, so every read and write sends a new request on each call.
* The Async methods of this object yield the calling script until the result is received. A failed request raises an error, so wrapping calls in pcall is recommended.

## Properties

## Methods

### GetAsync

Returns the value stored at the specified key.

If there is no item for the key or the item has expired, it returns nil without an error. If the request fails due to a server error or similar, it raises an error instead of returning nil.

This method yields the calling script until the result is received.

#### Parameters

| `string` InKey | The key of the item whose value to retrieve. Must be 1 to 128 characters long. |
| -------------- | ------------------------------------------------------------------------------ |

#### Return

| `Value` | The value stored at the key. nil if the item does not exist or has expired. |
| ------- | --------------------------------------------------------------------------- |

#### Code Samples

### ListItemsAsync

Returns a MemoryStoreHashMapPages object that lets you iterate through the stored items page by page.

This method yields the calling script until the first page is received.

**Important Notes**

* The iteration result is not a fixed snapshot taken at retrieval time. Items added during iteration may or may not appear, and the same item can appear more than once. However, items that exist throughout the iteration appear at least once.
* A page holding fewer items than the specified count does not mean it is the last page. Check IsFinished to determine whether it is the last page.

#### Parameters

| `number` InCount | <p>The maximum number of items per page.</p><ul><li>Must be between 1 and 200, and a value outside this range raises an error.</li><li>The specified value is a maximum, and a page does not always hold that many items.</li></ul> |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### Return

| `MemoryStoreHashMapPages` | <p>A MemoryStoreHashMapPages object holding the stored items divided into pages.</p><ul><li>GetCurrentPage() returns an array of tables with key and value fields.</li><li>If there are no stored items, GetCurrentPage() returns an empty table.</li></ul> |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### Code Samples

### RemoveAsync

Deletes the item with the specified key.

Deleting a key that does not exist succeeds without an error.

This method yields the calling script until the deletion is complete.

#### Parameters

| `string` InKey | The key of the item to delete. Must be 1 to 128 characters long. |
| -------------- | ---------------------------------------------------------------- |

#### Return

| `Value` | There is no return value (nil). |
| ------- | ------------------------------- |

#### Code Samples

### SetAsync

Saves a value at the specified key. If the key already has a value, it is overwritten unconditionally.

The expiration time is applied anew on every save, so an item that keeps being updated remains without expiring.

This method yields the calling script until the save is complete. A failed save raises an error.

#### Parameters

| `string` InKey       | The key of the item to save the value to. Must be 1 to 128 characters long.                                                                                                                                                                                                                                           |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Value` InValue      | <p>The value to save.</p><ul><li>Must be 1 to 32,768 bytes when serialized.</li><li>Omitting it or passing nil raises an error.</li></ul>                                                                                                                                                                             |
| `Value` InExpiration | <p>The expiration time of the item (in seconds).</p><ul><li>Must be between 0 and 3,888,000 seconds (45 days), and decimals can also be specified.</li><li>Specifying 0 makes the item expire immediately and be deleted.</li><li>There is no default value, so omitting it or passing nil raises an error.</li></ul> |

#### Return

| `Value` | true if an item already existed at the key before saving, false otherwise. |
| ------- | -------------------------------------------------------------------------- |

#### Code Samples

### UpdateAsync

Reads the current value of the specified key, transforms it with a callback function, and saves the result.

If another server or script changes the same key after the value is read but before it is saved, the latest value is read again and the callback runs again. This retry is performed up to 5 times or for up to 10 seconds, and an error is raised if the value cannot be saved within that limit.

This method yields the calling script until the save is complete.

**Important Notes**

* The callback runs again on every retry, so the number of executions is not guaranteed. Do not perform external actions inside the callback.
* If an error occurs inside the callback, the value is not changed and UpdateAsync raises an error.
* Calling UpdateAsync again on the same key inside the callback raises an error.
* The expiration time does not keep the expiration time of the existing item; it is applied anew with the InExpiration value on every update.

#### Parameters

| `string` InKey              | The key of the item whose value to update. Must be 1 to 128 characters long.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Value` InTransformFunction | <p>A function that receives the current value and returns a new value.</p><ul><li>Receives nil as its argument if the item does not exist or has expired.</li><li>Returning nil cancels the update, in which case UpdateAsync returns nil without an error.</li><li>If the returned value cannot be stored (a table with circular references, a type that cannot be stored, more than 32,768 bytes, etc.), an error is raised.</li><li>Passing a value that is not a function raises an error.</li></ul> |
| `Value` InExpiration        | <p>The expiration time of the updated item (in seconds).</p><ul><li>Must be between 0 and 3,888,000 seconds (45 days).</li><li>Even if the item already exists, this value is applied as the new expiration time.</li><li>Specifying 0 makes the item expire immediately and be deleted.</li><li>There is no default value, so omitting it or passing nil raises an error.</li></ul>                                                                                                                     |

#### Return

| `Value` | The new value that was saved. nil if the callback returned nil and canceled the update. |
| ------- | --------------------------------------------------------------------------------------- |

#### Code Samples

## Events
