我需要在单个 webapi 调用中使用不同的时间进行多次缓存。是否可以在 webapi 中使用内存缓存。
在Http缓存中,单次请求需要设置单次过期时间,有两种缓存,一种是5分钟,另一种是2小时单次http请求。
在 webapi 方法中设置了 5 分钟缓存,但是如果缓存不可用,它会打到其他外部服务 url 是:https://www.domain.com/api/sss/ss/ 但是 webapi 每次都应该调用,但是外部webapi 应该只调用缓存过期。这意味着在第 5 秒之后。webapi里面的2小时缓存,就是内存缓存。
public IHttpActionResult getProduct()
{
// cache for 5 minutes:
if( 5 min cache == null){
// call another services url
}
else{
// taken from 5 MIN cache.
}
// cache available take from 5 minutes cache data.
next : // cache for 2 hours
if(2 hours cache != null){
// get an original data
}
//cache available take from 2 hours cache data.
// add the values in single response as json.
return response;
}