-
|
ABP Framework version: 10.1 Problem: I have extended the Tenant entity by adding a new property named TenantStatus. If the TenantStatus is set to "Suspended", I want to prevent tenant resolution and block further request processing. To achieve this, I have implemented a custom middleware that checks the tenant status and blocks execution when the tenant is suspended. Currently, this requires querying the database on each request, which I want to avoid. Instead of querying the database, I would like to retrieve the TenantStatus from cache within the middleware. Can I use the Entity Cache feature described in the below documentation for this purpose? Is it appropriate to use entity cache for tenant data in middleware, or is there a better/recommended approach in ABP for this scenario? Expected guidance: Whether IEntityCache is suitable for this use case? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Whether IEntityCache is suitable for this use case?Yes. Any recommended patterns for caching tenant-related state in ABP middleware?Define a Also consider the built-in Best practices for keeping cache in sync when tenant status changes?
|
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the quick response. I think IsActive will not work for my case. Because I need to handle some other status too. If I use IEntityCache for my new field 'TenantStatus', will it cause any issue for the existing cache for the Tenant entity IDistributedCache TenantConfigurationCacheItem? |
Beta Was this translation helpful? Give feedback.
-
|
No, it won't cause any issue. Both will listen to |
Beta Was this translation helpful? Give feedback.
Whether IEntityCache is suitable for this use case?
Yes.
IEntityCachehandles automatic cache invalidation (viaEntityChangedEventData<Tenant>) and auto-loading from the repository on cache miss, which fits your scenario well.Any recommended patterns for caching tenant-related state in ABP middleware?
Define a
TenantStatusCacheItem, register it withAddEntityCache<Tenant, TenantStatusCacheItem, Guid>(), and injectIEntityCache<TenantStatusCacheItem, Guid>in your middlewareto check the status.
Also consider the built-in
IsActiveproperty onTenantConfiguration— if "Suspended" is essentially "inactive", settingIsActive = falselets ABP handle it automaticallywithout custom middleware.
B…