Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Playfab and Photon Chat : how do I properly implement a cache ?

Discussion in 'Multiplayer' started by tinoow, Jan 4, 2022.

  1. tinoow

    tinoow

    Joined:
    Nov 30, 2019
    Posts:
    3
    Hello everyone,

    I am developing a multiplayer game based on Photon PUN and Playfab.
    PUN deals with realtime data updates such as player position, animation etc.
    Playfab is used to store persistent data such as user groups, friend list, inventory etc. but these data can be updated multiple time per session.
    Retrieving this kind of data can be pretty heavy on the Playfab API calls limit : for example each time I need to display the groups in which a player is a member of equals to
    • 1 call to get the list of the player's group ids
    • 1 call for each of these ids to get their group name (or other infos...)
    To prevent that I cache most of these data on the client. My problem is that I need to know when another player updates this kind of data in order to update the concerned caches, but Playfab doesn't provide this option. I could make use of their PlayStream events which would then contact a middleware server that lists the connected players and tells them when a value has changed but it sounds too convoluted.

    My idea was to use a Photon Chat app :
    • if a player needs to access some kind of data he connects to a public channel regarding this kind of data (e.g. a channel named by a groupid)
    • when a player tells Playfab to change some of this data he also publish a message on the corresponding Photon Chat channel
    • and so every other player when receiving this kind of message know that this data is not up-to-date anymore and re-downloads it
    I would like to know if this could be a proper implementation for a cache system.
    Thanks in advance :D
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,971
    As Photon Chat has a fee for the CCUs of the app, I can't really say if this provides the net benefit you are after.
    In a room, players could tell the others to update their cache. Outside of game sessions, I think it might be good enough to infrequently check playfab.
     
  3. tinoow

    tinoow

    Joined:
    Nov 30, 2019
    Posts:
    3
    Thank you for your feedback, I forgot to mention that I will also use the Photon Chat app to implement a simple private chat and group chat system, so the CCUs will be there no matter what.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,971
    Ah, makes sense.
    I think over time, it may become quite spammy if everyone joins a channel and just "shouts" when (playfab) values were updated. If you only need to update the cache for known players, you could follow those others as friends. Then change the status, if values on playfab changed.