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

Clear client cache on-demand #35

Closed dahovey closed 4 years ago

dahovey commented 4 years ago

Hello,

I need to clear a client cached in Redis on-demand and I am having trouble. Consider an internal API that updates client configuration (in this case updating SQL Server backing store). After the update to SQL Server backing store is made clearing the client cache is required. Then on next request, the cache will be empty and the updated configuration is retrieved from SQL Server store.

I have tried to use the ICache<Client> and SetAsync using null as the client value but this doesn't clear the cache.

await _clientCache.SetAsync(clientId, null, TimeSpan.FromMilliseconds(1));

Is there some way I can successfully clear a specific client cache on demand?

I can imagine a few options:

Are either of these options feasible, or is there another way I can manually clear specific client cache?

I could create a pull request with one of these options, but didn't want to do work unnecessarily if another way is possible.

dahovey commented 4 years ago

I apologize, I now see #23 but would like to consider this again. If this library puts values in a cache I believe it should also be able to clear it.

Would you accept a PR implementing one of the above options?

dahovey commented 4 years ago

Ugh, I had a namespace mix-up where the ICache<T> generic type was that of the EntityFramework object not the IdentityServer.Models.*

This seems to resolve my issue with clearing cache for specific client.