0
bozkan created
Hi,
Is it possible to access host cache from tenant via IDistributedCache?
ps: I cannot use IgnoreMultiTenancyAttribute for the cached type, because it is Identity Server's type and cache for the type: IdentityServer4.Models.Client
6 Answer(s)
-
0
hi
Can you try to switch the current tenant?
using (CurrentTenant.Change(tenantId)) { //IDistributedCache<IdentityServer4.Models.Client> Cache }
-
0
Hi maliming,
Thanks for the reply. The situation is:
using (CurrentTenant.Change(null)) { // GetAsync works on host! It gets cached item from host. var cachedClient = await _clientCache.GetAsync(identityClient.ClientId); cachedClient.Enabled = false; // But SetAsync does not work on host! It adds a new cached item under tenant folder on redis. // Instead of overwriting the item on host folder. await _clientCache.SetAsync(identityClient.ClientId, cachedClient, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = _identityServerOptions.Caching.ClientStoreExpiration }, considerUow: true); }
-
0
Can you try
considerUow: false
-
0
Yeap. When considerUow: false, it works!
What is the reason of this behavior? Should I give up on considerUow? But I need it, because I execute this cache update together with some database operation .
-
0
hi
You can create a new unit of work.
using (CurrentTenant.Change(null)) { using (var uow = _unitOfWorkManager.Begin( requiresNew: true )) { // GetAsync works on host! It gets cached item from host. var cachedClient = await _clientCache.GetAsync(identityClient.ClientId); cachedClient.Enabled = false; // But SetAsync does not work on host! It adds a new cached item under tenant folder on redis. // Instead of overwriting the item on host folder. await _clientCache.SetAsync(identityClient.ClientId, cachedClient, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = _identityServerOptions.Caching.ClientStoreExpiration }, considerUow: true); await uow.CompleteAsync(); } }
-
0
Thank you