Cache Set
API for setting cache values.
URL Confirmation
This API uses the service-api.playnanoo.com domain.
API Information
- URL:
https://service-api.playnanoo.com/cache/v20241201/set - Method:
PUT - Authentication Required: Yes
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| cache_key | string | Required | Cache key |
| cache_value | string | Required | Cache value |
| cache_ttl | string | Required | Cache TTL (in seconds) |
DeviceInfo Inheritance
The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.
Response Data
Res Class
| Field | Type | Description |
|---|---|---|
| Status | string | Processing status |
Unity C# Implementation
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;
}
}
Usage Example
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 failed: [{error.ErrorCode}] [{error.Message}]");
}
));
}