Cleaning cache for specific object

Options

Hello!

I use RaiseEvent for interacting with specific objects. All events are added to the room cache. But when I finish interacting with this object I don't want to have all raised earlier events to be in cache. All my objects have a unique ID so I want to clear the cache only for objects with this ID. Here is an example of code where I Raise events.

private void RaiseWebEvent(bool isReliable, ReceiverGroup receiverGroup, params object[] data)
{
    var hashtableData = new Hashtable {{worldViewID, data}};

    var raiseEventOptions = new RaiseEventOptions
    {
        Receivers = receiverGroup,
        CachingOption = EventCaching.AddToRoomCache
    };

    var sendOptions = new SendOptions
    {
        Reliability = isReliable
    };

    Logging.Log($"Raise event from canvas web view {(string) data[0]}");


    PhotonNetwork.RaiseEvent(NetworkingModel.WebScreenEventCode, hashtableData,
        raiseEventOptions,
        sendOptions);
}

worldview is the ID of this specific object.

Then how can I clear all cached events only for this specified object?

Here is my code where I receive events

public async void OnEvent(EventData photonEvent)
{
    if (photonEvent.Code == NetworkingModel.WebScreenEventCode)
    {
        Logging.Log($"Calling event with code {photonEvent.Code}");

        if (uniqueId == null)
            return;

        if (string.IsNullOrEmpty(uniqueId.Id))
        {
            Logging.LogWarning("unique ID is empty");
            return;
        }

        var hashtableData = (Hashtable) photonEvent.CustomData;

        if (!hashtableData.ContainsKey(uniqueId.Id))
            return;

        var data = (object[]) hashtableData[uniqueId.Id];

        var webEvent = (string) data[0];

        switch (webEvent)
        {
            case WebEvents.PowerOn:
                await CreateWebView();

                break;

            case WebEvents.TakeControl:
                var userName = (string) data[1];

                SetControlledByUser(userName);
                break;

            case WebEvents.URLChanged:
                var newUrl = (string) data[1];

                await webViewScreen.WaitUntilInitialized();

                webViewScreen.WebView.LoadUrl(newUrl);
                break;

            case WebEvents.Click:
                var normalizedPoint = (Vector2) data[1];

                await webViewScreen.WaitUntilInitialized();

                webViewScreen.WebView.Click(normalizedPoint, true);
                break;

            case WebEvents.Scroll:
                var normalizedScrollDelta = (Vector2) data[1];
                var point = (Vector2) data[2];

                await webViewScreen.WaitUntilInitialized();

                webViewScreen.WebView.Scroll(normalizedScrollDelta, point);
                break;

            case WebEvents.KeyDown:
                var keyDownArguments = JsonConvert.DeserializeObject<KeyboardInputEventArgs>((string) data[1]);

                if (webViewWithKeyDownAndUp != null)
                {
                    webViewWithKeyDownAndUp.KeyDown(keyDownArguments.Value, keyDownArguments.Modifiers);
                }
                else
                {
                    await webViewScreen.WaitUntilInitialized();

                    webViewScreen.WebView.SendKey(keyDownArguments.Value);
                }

                break;

            case WebEvents.KeyUp:
                var keyUpArguments = JsonConvert.DeserializeObject<KeyboardInputEventArgs>((string) data[1]);

                webViewWithKeyDownAndUp?.KeyUp(keyUpArguments.Value, keyUpArguments.Modifiers);

                break;

            case WebEvents.PowerOff:
                PowerOff();

                var eventOptions = new RaiseEventOptions {CachingOption = EventCaching.RemoveFromRoomCache};

                var cachedData = new Hashtable() //What should I pass into this hashtable?

                PhotonNetwork.RaiseEvent(NetworkingModel.WebScreenEventCode, cachedData, eventOptions,
                    SendOptions.SendReliable);

                break;
        }

        Logging.LogFormat("Recived event with web code {0}", webEvent);
    }
}

Here in case PowerOff I want to clear all cached events. I saw a topic about cached events but I think I didn't get this part "Use case 2: If you use a Hashtable as event content, you can mark all events belonging to some object with an "oid" key (short form of "ObjectID") and some value. When you want to clean up the cache related to a specific object, you can just send a Hashtable(){"oid", <objectId>} as event data filter and EventCaching.RemoveFromRoomCache."

Comments

  • Delpriore
    Options

    I added code to collect all my events into the list after sending them, and then I made each loop for clearing all those managed events. But it seems that it doesn't work. Because I still received them.