Skip to content

Commit

Permalink
Fixing issue with asynchronous handler
Browse files Browse the repository at this point in the history
This might have been the underlying issue all along
  • Loading branch information
Turnerj committed Nov 13, 2020
1 parent 3b40086 commit 51d5424
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/CacheTower.Extensions.Redis/RedisRemoteEvictionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ public void Register(ICacheStack cacheStack)
}
IsRegistered = true;

Subscriber.Subscribe(RedisChannel, async (channel, value) =>
{
string cacheKey = value;
var shouldEvictLocally = false;
lock (FlaggedRefreshesLockObj)
Subscriber.Subscribe(RedisChannel, CommandFlags.FireAndForget)
.OnMessage(async (channelMessage) =>
{
shouldEvictLocally = FlaggedRefreshes.Remove(cacheKey) == false;
}
string cacheKey = channelMessage.Message;
var shouldEvictLocally = false;
lock (FlaggedRefreshesLockObj)
{
shouldEvictLocally = FlaggedRefreshes.Remove(cacheKey) == false;
}

if (shouldEvictLocally)
{
await cacheStack.EvictAsync(cacheKey);
}
}, CommandFlags.FireAndForget);
if (shouldEvictLocally)
{
await cacheStack.EvictAsync(cacheKey);
}
});
}
}
}

0 comments on commit 51d5424

Please sign in to comment.