缓存设置
设置缓存值的 API。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/cache/v20241201/set - Method:
PUT - 需要认证: 是
请求参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
| cache_key | string | 必需 | 缓存键 |
| cache_value | string | 必需 | 缓存值 |
| cache_ttl | string | 必需 | 缓存 TTL(以秒为单位) |
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| Status | string | 处理状态 |
Unity C# 实现
using System;
using System.Collections;
using UnityEngine.Networking;
public class CacheSet
{
static string path = "https://service-api.playnanoo.com/cache/v20241201/set";
[Serializable]
public class Req : DeviceInfo
{
public string cache_key;
public string cache_value;
public string cache_ttl;
public IEnumerator Send(string cache_key, string cache_value, int cache_ttl, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(cache_key)) this.cache_key = cache_key;
if (!string.IsNullOrEmpty(cache_value)) this.cache_value = cache_value;
this.cache_ttl = cache_ttl.ToString();
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string Status;
}
}
使用示例
public void SetCache()
{
CacheSet.Req req = new CacheSet.Req();
StartCoroutine(req.Send(
cache_key: "player_level",
cache_value: "50",
cache_ttl: 3600,
onSuccess: res =>
{
Debug.Log($"Set success: {res.Status}");
},
onError: (error) =>
{
Debug.LogError($"Set 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}