Base solution for your next web application
Open Closed

Redis not being updated when add a friend, chat feature dies #5419


User avatar
0
kyckradmin created

Hi Folks, When a new friend is added to a user, the users cache is not being updated when using the Redis cache manager. If using an InMemory cache then everything works fine.

This code snippet below, updates the user item with a new friend, but it does not write this back to the cache anywhere. I also can't see any methods on the userFriendCache interface for writing to the cache. Where is the best place to do this?

This cause problems in a clustered environment, we currently have a 5 node cluster, the only way we can get the users cache to update correctly is to stop the cluster and restart. This then will pickup the new friends associated with the user when it is loaded from the database. The chat feature is basically unusable with this issue.

public void AddFriend(UserIdentifier userIdentifier, FriendCacheItem friend)
        {
            var user = GetCacheItemOrNull(userIdentifier);
            if (user == null)
            {
                return;
            }
            lock (_syncObj)
            {
                if (!user.Friends.ContainsFriend(friend))
                {
                    user.Friends.Add(friend);
                }
            }
        }

Kind Regards Noel


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks for your report. I have created an issue <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/1466">https://github.com/aspnetzero/aspnet-ze ... ssues/1466</a>. We will fix this for v5.6 release.

    You can use something like this after AddFriend line;

    _cacheManager.GetCache(FriendCacheItem.CacheName).Set(userIdentifier.ToUserIdentifierString(), user);