How to remove/replace an event in the global cache?
According to the cached events documentation it is possible to remove events from the global cache, but I have been unable to find an API that accomplishes that. The list of available event caching values shows a value for adding to the global cache, but not a corresponding value for removing or replacing an event in the global cache. How do I accomplish this?
0
Best Answer
-
Hi @Bob_F,
You can remove events from global cache.
You cannot replace directly, but you can remove and (re)add again.
If the events in the global cache have unique event codes then use those event codes as filters when removing the event from cache using EventCaching.RemoveFromRoomCache.
If the events in the global cache have unique data (total or partial) use that as a filter when removing the event from cache using EventCaching.RemoveFromRoomCache.
Otherwise, set target actors to array with one element 0 to use that as a filter when removing the event from cache using EventCaching.RemoveFromRoomCache.
The filer here to remove events from cache is based on the sender actor number and it is set via target actors array (of actor numbers).
And to specify that we want to remove events from global cache we specify their sender actor number as 0 which usually refers to the "room". (no actor)
so something like this (I hope I did not massacre JavaScript too much)loadBalancingClient.raiseEvent(0, null, { targetActors: [0], cache: EventCaching.RemoveFromRoomCache });
5
Answers
-
Hi @Bob_F,
You can remove events from global cache.
You cannot replace directly, but you can remove and (re)add again.
If the events in the global cache have unique event codes then use those event codes as filters when removing the event from cache using EventCaching.RemoveFromRoomCache.
If the events in the global cache have unique data (total or partial) use that as a filter when removing the event from cache using EventCaching.RemoveFromRoomCache.
Otherwise, set target actors to array with one element 0 to use that as a filter when removing the event from cache using EventCaching.RemoveFromRoomCache.
The filer here to remove events from cache is based on the sender actor number and it is set via target actors array (of actor numbers).
And to specify that we want to remove events from global cache we specify their sender actor number as 0 which usually refers to the "room". (no actor)
so something like this (I hope I did not massacre JavaScript too much)loadBalancingClient.raiseEvent(0, null, { targetActors: [0], cache: EventCaching.RemoveFromRoomCache });
5 -
Thanks, @JohnTube, that's an interesting solution!
I ended up solving my problem by using custom room properties to broadcast and store my events, rather than the global event cache. That allows me to simply overwrite old events with new events by using the event code as a property key. The other players are then automatically notified via onPropertiesChange. That solution would not necessarily work well for everyone, but it seems to work pretty well for my particular case and it was easy to implement. I appreciate knowing your solution though since I may have need for it as I get deeper into my project. Thanks again!0