Clear event cache in channel
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Clear event cache in channel
Nick89
2018-10-18 13:59:49
Hi, everyone.
For a multiplayer project i am doing, i need to cache events in the room, so that events are sent to players even if they join later.
I would like to clear the event cache, so that old events that are no more needed in the room are not sent when a new player join.
The problem here is that, in some cases, multiple events that are indipendent one from the other should be sent at the same time when a new player joins, so i should not simply clear the cache and send just one event at time.
One solution i found to this is to use sequence channels : i could group the events in channel, and when i want to send a new event, i could choose a channel and remove ONLY the events in that channel, before raising a new one.
Reading documentation and examples online, the only way i found to this is the following, but it is not working :
for (byte i = 0; i < (byte) ENetworkEvent.MAX; i++)
{
PhotonNetwork.RaiseEvent(i, null, true, new RaiseEventOptions { CachingOption = EventCaching.RemoveFromRoomCache, SequenceChannel = (byte)eventType });
}
PhotonNetwork.RaiseEvent(code, message, true, new RaiseEventOptions { CachingOption = EventCaching.AddToRoomCacheGlobal, SequenceChannel = (byte)eventType });</i>
It should just clear the events in channel, but it seems to clear the entire cache.
What am i doing wrong ?
Thanks in advance for any help
Comments
[Deleted User]
2018-10-18 15:09:07
Hi @Nick89,
the problem seems to be, that you iterate through each possible custom event code and remove the related event from the server's cache. Try to remove the for-loop and only remove certain cached events. You can also take a look at the Cached Events documentation page and see if this gives you further insights.
@Christian_Simon wrote:
Hi @Nick89,
the problem seems to be, that you iterate through each possible custom event code and remove the related event from the server's cache. Try to remove the for-loop and only remove certain cached events. You can also take a look at the Cached Events documentation page and see if this gives you further insights.
Yes, but i need to remove only the events in a specific channel. How can i find all the events belonging to a channel ?
Up
Hi @Nick89,
Thank you for choosing Photon!
What you need is Cache Slice and not Sequence Channel.
You can cache events only in the currently selected cache per room.
Anyone can increase or change/set the cache slice index at any time.
You can remove/purge cached events from a specific cache only.
You can purge cached events for all slices up to a certain index.
You could specify which slice to set when joining a room.
This is available only in the native SDKs I think.
This is partially available in other C# SDKs.
It's also not documented.
You could find more info on the forum.
@JohnTube wrote:
Hi @Nick89,
Thank you for choosing Photon!
What you need is Cache Slice and not Sequence Channel.
You can cache events only in the currently selected cache per room.
Anyone can increase or change/set the cache slice index at any time.
You can remove/purge cached events from a specific cache only.
You can purge cached events for all slices up to a certain index.
You could specify which slice to set when joining a room.This is available only in the native SDKs I think.
This is partially available in other C# SDKs.It's also not documented.
You could find more info on the forum.
Ok, i am trying to understand the slice logic by myself.
Just to figure out if i understood correctly :
1)SliceSetIndex : does the "index" refer to eventContent parameter in PhotonNetwork.RaiseEvent ?
2)SlicePurgeIndex : does it removes all the events in specified index ?
Also, the documentation says that you need to set CacheSliceIndex in RaiseEventOptions class, but i could not find it as member of the class !
- Yes. there should be a RaiseEventOptions.CacheSliceIndex. but it's not there now in the C#/.NET SDKs
- Yes.