# 使用Memory或Redis缓存

//以SellOrderService为例,在构造方法中获取对象

[ActivatorUtilitiesConstructor]
private ICacheService _cacheService;
public SellOrderService(ICacheService cacheService)
{
    //默认使用的内存缓存,如果需要使用redis将appsetting.json中设置UseRedis:"true"
    _cacheService = cacheService;
    //HttpContext.Current.GetService<ICacheService>()
    //base.CacheContext (仅限表xxx.Serivce.cs)
}
1
2
3
4
5
6
7
8
9
10
11