Browse Source

Update POST.md

pull/21233/head
EngincanV 2 years ago
parent
commit
e66e1e7187
  1. 28
      docs/en/Community-Articles/2024-11-01-Hybrid-Cache-Net-9/POST.md

28
docs/en/Community-Articles/2024-11-01-Hybrid-Cache-Net-9/POST.md

@ -29,6 +29,9 @@ To demonstrate how to use **HybridCache** in ABP, let's start with a simple exam
First, you can configure the hybrid cache options in your module class as below (it's optional): First, you can configure the hybrid cache options in your module class as below (it's optional):
```csharp ```csharp
using Microsoft.Extensions.Caching.Hybrid;
using Volo.Abp.Caching.Hybrid;
public class YourModule : AbpModule public class YourModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
@ -38,7 +41,7 @@ public class YourModule : AbpModule
Configure<AbpHybridCacheOptions>(options => Configure<AbpHybridCacheOptions>(options =>
{ {
//configuring the global hybrid cache options //configuring the global hybrid cache options
option.GlobalHybridCacheEntryOptions = new HybridCacheEntryOptions() options.GlobalHybridCacheEntryOptions = new HybridCacheEntryOptions()
{ {
Expiration = TimeSpan.FromMinutes(20), Expiration = TimeSpan.FromMinutes(20),
LocalCacheExpiration = TimeSpan.FromMinutes(10) LocalCacheExpiration = TimeSpan.FromMinutes(10)
@ -56,24 +59,14 @@ public class YourModule : AbpModule
After the configuration, now you can inject the `IHybridCache` and use it to set and retrieve cache values: After the configuration, now you can inject the `IHybridCache` and use it to set and retrieve cache values:
```csharp ```csharp
public class BookCacheItem using Volo.Abp.Caching.Hybrid;
{
public string Name { get; set; }
public int PageCount { get; set; }
}
public class BookAppService : IBookAppService, ITransientDependency public class BookAppService : ApplicationService, IBookAppService
{ {
private readonly IBookRepository _bookRepository;
private readonly IHybridCache<BookCacheItem> _hybridCache; private readonly IHybridCache<BookCacheItem> _hybridCache;
public BookAppService( public BookAppService(IHybridCache<BookCacheItem> hybridCache)
IBookRepository bookRepository,
IHybridCache<BookCacheItem> hybridCache
)
{ {
_bookRepository = bookRepository;
_hybridCache = hybridCache; _hybridCache = hybridCache;
} }
@ -93,6 +86,13 @@ public class BookAppService : IBookAppService, ITransientDependency
}); });
} }
} }
public class BookCacheItem
{
public string Name { get; set; }
public int PageCount { get; set; }
}
``` ```
* You can use the `IHybridCache<TCacheItem>` or `IHybridCache<TCacheItem, TCacheKey>` service to leverage the hybrid caching. If you use `IHybridCache<TCacheItem>`as the service, then you should pass the cache key as *string* like in the example above. * You can use the `IHybridCache<TCacheItem>` or `IHybridCache<TCacheItem, TCacheKey>` service to leverage the hybrid caching. If you use `IHybridCache<TCacheItem>`as the service, then you should pass the cache key as *string* like in the example above.

Loading…
Cancel
Save