Store

A Store exposes methods to read and write data with no need to input key as it should already be bound when creating the Store.

Explanation:

  • bypassId parameter is optional. When the Store is froze or locked, bypassId could be used to bypass the restrictions if it is correct.

Methods

:Read(cacheData: boolean?, bypassId: string?): any?, DataStoreKeyInfo? (yields)

Retrieves data associated with the key. If cacheData is true or nil, data will be cached. Future requests will priortize reading cache if any is available.

:Write(value: any?, bypassId: string?): boolean? (yields)

Overwrites the data associated with the key with the given value.

:AddUserIds(userIds: string | number | {string} | {number}) (server-wide)

Add UserIds that will be sent along with future :Write() requests.

:RemoveUserIds(userIds: string | number | {string} | {number}) (server-wide)

Remove UserIds from the list.

:SetMetaData(metaData: any?) (server-wide)

Sets the MetaData to send along with future :Write() requests.

:GetKeyState(): string (yields)

Retrieves the State of the key in string:

  • "Normal": All operations and requests associated with the Store is accessible and callable.

  • "Froze": The Store will be read-only, meaning most writing operations associated with the Store will be inaccessible.

  • "Locked": Most operations will be inaccessible, except for versioning and state operations.

This method is not affected by the state of the store.

:SetKeyState(state: string | number) (yields)

Overwrites the State of the key with the given state. The state parameter can be either a string or a number, note the following:

  • 0 == Normal

  • 1 == Froze

  • 2 == Locked

This method is not affected by the state of the store.

:Purge(bypassId: string?) (yields)

Purges all data associated with the Store.

:ListVersions(isDescending: boolean?, minDate: DateTime | number, maxDate: DateTime | number): {[string]: string}? (yields)

List all versions of data associated with the store from minDate to maxDate in a dictionary in the given sort order (isDescending defaults to true).

The returned dictionary should either be empty or follow the format:

{
    [VersionId: string] = Created_Time_Of_The_Version: string,
    ...
}

A detailed usage is shown in Reverting data to a certain version. This method is not affected by the state of the store.

:GetVersionWithId(versionId: string): any?, DataStoreKeyInfo? (yields)

Returns the value and DataStoreKeyInfo associated with the version provided, if any. This method is not affected by the state of the store.

:GetVersionAtTime(time: DateTime | number): any?, DataStoreKeyInfo? (yields)

Returns the latest version in respect of the time parameter. The provided time must not be more than 10 minutes in the future in comparison to the creation time of the version due to Roblox's engine's limitations. This method is not affected by the state of the store.

:RemoveVersion(versionId: string): boolean? (yields)

Removes the version associated with the versionId. The version and its data cannot be retrieved later. This method is not affected by the state of the store.

:End() (server-wide)

Clears all local cache and ends the store

Events

DataCached

Fires when data has been cached for :Read() operations.

Parameters

Value: any?

The data that has been cached.

CacheRemoved

Fires when cache has been removed from the list. This does not fire when the cache is replaced.

Parameters

Value: any?

The data that has been removed from the cache list.

IsRead

Fires when data has been successfully retrieved from the store. This also fires when cache is read.

Parameters

Value: any?

The data that has been read.

IsCache: boolean

True when cache is read instead of data retrieved with a network call.

Written

Fires when data is overwritten with :Write() .

Parameters

Value: any?

The value used to overwrite the data.

IsCache: boolean

True when Value is same as the one of the last :Write() call and the current network call is voided.

KeyStateChanged

FIres when the state of the store is changed.

Parameters

State: string

The update state of the store. Must be either of the following: - "Normal" - "Froze" - "Locked"

DefaultUsed

Fires when the default value has replaced the value returned by :Read() (which in this case is nil).

VersionRemoved

Fires when a version has been removed from the store, which should been done by :RemoveVersion()

Parameters

VersionId: string

The identifier of the removed version.

Purged

Fires when :Purge() has been successfully called.

Ended

Fires when :End() has been successfully called.

Last updated