Skip to main content

InMemoryDataStore

This item only works when running on the server. Server

A DataStoreStage root that lives entirely in memory: it is never backed by a Roblox datastore, so nothing it holds is ever written or read across sessions. Reads resolve to whatever has been staged in memory (defaults when unset) and writes stay local to this object, vanishing when it is destroyed.

Every read/write/substore/observe method comes from DataStoreStage unchanged -- the base class computes its view purely from in-memory snapshots. The only thing a stage normally needs a parent for is DataStoreStage.PromiseViewUpToDate (loading its base layer from the datastore above it); a root has no parent, so this class resolves that immediately against its own view. That single override is the whole difference between this and DataStore, which loads/saves through Roblox.

Use it wherever code wants a real store surface for data that must not persist -- e.g. a throwaway session slot -- without paying for DataStore's load, save, autosave, and session-locking machinery.

local store = InMemoryDataStore.new()
store:Store("coins", 5)
print(store:Load("coins"):Yield()) -- 5, never touches a datastore

Functions

new

InMemoryDataStore.new(
loadName(string | number)?--

diagnostic name only (see DataStoreStage.GetFullPath); defaults to "InMemoryDataStore"

) → InMemoryDataStore

Constructs a new in-memory data store.

PromiseViewUpToDate

InMemoryDataStore.PromiseViewUpToDate(_selfInMemoryDataStore) → Promise

The view is always exactly what has been staged in memory, so it is never out of date: there is no parent or datastore to sync from. Overriding this (the base class errors on a parentless stage) is what makes every inherited read work in-memory.

Save

InMemoryDataStore.Save(_selfInMemoryDataStore) → Promise

A no-op that resolves: there is no backing datastore to flush to. Present so this is a drop-in root for code that expects to be able to call :Save() on its store.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new in-memory data store.",
            "params": [
                {
                    "name": "loadName",
                    "desc": "diagnostic name only (see [DataStoreStage.GetFullPath]); defaults to \"InMemoryDataStore\"",
                    "lua_type": "(string | number)?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "InMemoryDataStore"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 45,
                "path": "src/datastore/src/Server/InMemoryDataStore.lua"
            }
        },
        {
            "name": "PromiseViewUpToDate",
            "desc": "The view is always exactly what has been staged in memory, so it is never out of date: there is no\nparent or datastore to sync from. Overriding this (the base class errors on a parentless stage) is what\nmakes every inherited read work in-memory.",
            "params": [
                {
                    "name": "_self",
                    "desc": "",
                    "lua_type": "InMemoryDataStore"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 59,
                "path": "src/datastore/src/Server/InMemoryDataStore.lua"
            }
        },
        {
            "name": "Save",
            "desc": "A no-op that resolves: there is no backing datastore to flush to. Present so this is a drop-in root for\ncode that expects to be able to call `:Save()` on its store.",
            "params": [
                {
                    "name": "_self",
                    "desc": "",
                    "lua_type": "InMemoryDataStore"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 69,
                "path": "src/datastore/src/Server/InMemoryDataStore.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "InMemoryDataStore",
    "desc": "A [DataStoreStage] root that lives entirely in memory: it is never backed by a Roblox datastore, so\nnothing it holds is ever written or read across sessions. Reads resolve to whatever has been staged in\nmemory (defaults when unset) and writes stay local to this object, vanishing when it is destroyed.\n\nEvery read/write/substore/observe method comes from [DataStoreStage] unchanged -- the base class computes\nits view purely from in-memory snapshots. The only thing a stage normally needs a parent for is\n[DataStoreStage.PromiseViewUpToDate] (loading its base layer from the datastore above it); a root has no\nparent, so this class resolves that immediately against its own view. That single override is the whole\ndifference between this and [DataStore], which loads/saves through Roblox.\n\nUse it wherever code wants a real store surface for data that must not persist -- e.g. a throwaway session\nslot -- without paying for [DataStore]'s load, save, autosave, and session-locking machinery.\n\n```lua\nlocal store = InMemoryDataStore.new()\nstore:Store(\"coins\", 5)\nprint(store:Load(\"coins\"):Yield()) -- 5, never touches a datastore\n```",
    "realm": [
        "Server"
    ],
    "source": {
        "line": 25,
        "path": "src/datastore/src/Server/InMemoryDataStore.lua"
    }
}