# SPersistence

**成员** 6

|      |                                             |                                                                           |
| ---- | ------------------------------------------- | ------------------------------------------------------------------------- |
| 函数 | [UpdateInfo](#updateinfo)                   | Call the onComplete function upon the server saving a value.              |
| 函数 | [RetrieveValue](#retrievevalue)             | Returns the saved value with the key.                                     |
| 函数 | [SetValue](#setvalue)                       | Save a value to the storage record that is accessed with key.             |
| 函数 | [UpdateRegionInfo](#updateregioninfo)       | Updates your local cache with the most up-to-date values from the server. |
| 函数 | [RetrieveRegionValue](#retrieveregionvalue) | Retrieves the saved value from "key" from your local cache.               |
| 函数 | [SetRegionValue](#setregionvalue)           | Save the "value" to "key" on both your local cache and on the server.     |

## 函数

### UpdateInfo

void UpdateInfo(Closure onComplete)

Call the onComplete function upon the server saving a value.

参数

| 名称       | 类型    | 默认值 |
| ---------- | ------- | ------ |
| onComplete | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
function OnCompleteFunction()
--
end

Space.Persistence.UpdateInfo(OnCompleteFunction)

```

**Lua**

```lua
Space.Persistence.SetValue("TestValue","123");

Space.Persistence.UpdateInfo(function ()
    local value = Space.Persistence.RetrieveValue("TestValue")
    Space.Log(value)
end)
--print "123" to console.

```

### RetrieveValue

string RetrieveValue(string key)

Returns the saved value with the key.

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| key  | string | –      |

返回值

`string`

示例

**Lua**

```lua
Space.Persistence.RetrieveValue("TestValue")

```

### SetValue

void SetValue(string key, string value)

Save a **value** to the storage record that is accessed with **key**.

参数

| 参数  | 类型   | 说明           |
| ----- | ------ | -------------- |
| key   | string | Max length 48  |
| value | string | Max length 255 |

返回值

`void`

示例

**Lua**

```lua
Space.Persistence.SetValue("MyValue", "Hello World");

```

### UpdateRegionInfo

void UpdateRegionInfo(Action onComplete)

void UpdateRegionInfo(Closure onComplete)

Updates your local cache with the most up-to-date values from the server. This function should be called before using the [*RetrieveRegionValue*](/docs/zh-Hans/scripting/client-scripting-api-reference/region/spersistence.md#retrieveregionvalue) function.

参数

| 名称       | 类型    | 默认值 |
| ---------- | ------- | ------ |
| onComplete | Action  | –      |
| onComplete | Closure | –      |

返回值

`void`

示例

**Lua**

```lua
Space.Persistence.SetRegionValue("TestRegionValue","456")

Space.Persistence.UpdateRegionInfo(function ()
    local value = Space.Persistence.RetrieveRegionValue("TestRegionValue")
    Space.Log(value)
end)
--print "456" to console.

```

### RetrieveRegionValue

string RetrieveRegionValue(string key)

Retrieves the saved value from "key" from your local cache. The [*UpdateRegionInfo* ](/docs/zh-Hans/scripting/client-scripting-api-reference/region/spersistence.md#updateregioninfo)function should be called first to update your local cache with the most up-to-date values from the server.

参数

| 名称 | 类型   | 默认值 |
| ---- | ------ | ------ |
| key  | string | –      |

返回值

`string`

示例

**Lua**

```lua
Space.Persistence.RetrieveRegionValue("TestRegionValue");

```

### SetRegionValue

void SetRegionValue(string key, string value)

Save the "value" to "key" on both your local cache and on the server.

参数

| 参数  | 类型   | 说明           |
| ----- | ------ | -------------- |
| key   | string | Max length 48  |
| value | string | Max length 255 |

返回值

`void`

示例

**Lua**

```lua
Space.Persistence.SetRegionValue("TestRegionValue","456");

```
