AliBazzi / IdentityServer4.Contrib.RedisStore

A persistence layer using Redis DB for operational data and for caching capability for Identity Server 4
https://www.nuget.org/packages/IdentityServer4.Contrib.RedisStore
MIT License
137 stars 48 forks source link

Is there a way to clear the RedisCache programmatically? #23

Closed javaadpatel closed 5 years ago

javaadpatel commented 5 years ago

Hi,

I am using the RedisCaching via:

 .AddRedisCaching(options =>
                {
                    options.RedisConnectionMultiplexer = DefaultRedisConnection;
                    options.KeyPrefix = $"StoreCache_{Configuration[SubTenantID]}_";
                    options.Db = 1;
                })

is there an easy way to clear the cache? For example after an update to the client model, the cache will have a stale client model.

I used the stackexchange library to delete the keys associated with the Store like:

  var keys = await Client.SearchKeysAsync($"{_storeKeys}*");
                await Client.RemoveAllAsync(keys);
                return true;

but I am not sure if your library or IdentityServer has a cleaner way to do this.

AliBazzi commented 5 years ago

the easiest would be to wait until the cached client model expires, usually I would say to the consumers please allow x minutes for the changes to take effect, where x is what you configured on identity server options.

What you are talking about is aggressive update of the cache, this is harder to implement and is beyond the scope of the library or identity server.

javaadpatel commented 5 years ago

@AliBazzi yep I was looking for a standard way to aggressively update the cache. Okay awesome, thank you for the help.