question

Chase avatar image
Chase asked

[TypeScript CloudScript] - Best practices for keeping track of user data as it changes?

Hello,

I have my player's executing a cloudscript function every time they try to equip something, to allow for item validation. This all occurs within their inventory screen. I'm wanting to have the cloudscript side to store relevant data that changes, as it changes. To keep it and cache it, then save it off until the player exits their inventory screen, to prevent DataUpdateRateExceeded errors.

What is a best practice in TypeScript to maintain persistent cached data for a player to keep track of these changes? Ideally it would be nice to have a cached dictionary that maps from currentPlayerId -> corresponding data. Where after the player exits their inventory this data gets saved off and then cleared from this dictionary.

Thanks for the advice.

CloudScriptdata
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chase avatar image Chase commented ·

Update: I'm currently in the process of getting a redis cache setup to solve this

0 Likes 0 ·
Chase avatar image Chase commented ·

I'm looking at this for getting data in & out in Azure Redis Cache documentation: https://docs.microsoft.com/en-us/rest/api/redis/redis/importdata & https://docs.microsoft.com/en-us/rest/api/redis/redis/exportdata

It looks like the REST api is fairly minimal here, is there a different approach or redis client that can be used in cloudscript? Or are we limited to http.request? What I'm seeing looks like you just store a bunch of bulk data and then retrieve a bunch of bulk data. I thought you could separate into chunks by key values in redis.

This would work, but it's not ideal, I could see the data set getting fairly large. This documentation looks like an administration api. Am I missing something?

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

>> What is a best practice in TypeScript to maintain persistent cached data for a player to keep track of these changes?

As this thread -- https://community.playfab.com/questions/39713/is-it-possible-to-set-a-local-variable-as-a-value.html said. Each time you call the ExecuteCloudScript API, you should assume the CloudScript function instance has no information from previous executions. CloudScript itself can’t be used to store data. As you mentioned, in your case, an external cache such as Redis is required.

>> It looks like the REST api is fairly minimal here, is there a different approach or redis client that can be used in cloudscript? Or are we limited to http.request?

In CloudScript, http.request is the only option you can use to call the Redis API. CloudScript doesn’t provide the encapsulation of other network methods. PlayFab CloudScript isn't integrated with Azure Redis too. If integrating CloudScript with Azure Redis is necessary for you, you can try to add a feature request for it.

Besides, you can consider using PlayFab CloudScript using Azure Functions which can be written usingC# and the other supported Azure Functions languages. For example when you use C#, you can add the reference of StackExchange.Redis to use the Redis client.

>> This would work, but it's not ideal, I could see the data set getting fairly large. This documentation looks like an administration api. Am I missing something?

Do you mean the Azure Redis’s documentation? PlayFab forum focuses on solving PlayFab technical questions. If you have any questions about Azure Redis, you refer to this documentation to use Azure Community Support.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chase avatar image Chase commented ·

Thanks Sarah - this is great information. I did end up setting up an Azure Functions app, and an Azure Cache for Redis as well as corresponding get & set http requests to there from cloudscript. It seems to work, but definitely noticing added delay which is concerning. I'll have to look into increasing my Azure tier or something in the near future if that's the cause. Not entirely sure.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.