生产环境中 webapi2 的内存缓存测试或 QA 测试



如何在生产或 QA 环境中测试内存中缓存逻辑。

//If the data exists in cache, pull it from there, otherwise make a call to database to get the data
ObjectCache cache = MemoryCache.Default;
var peopleData = cache.Get("PeopleData") as List<People>;
if (peopleData != null)
   return peopleData ;
peopleData = GetAllPeople();
CacheItemPolicy policy = new CacheItemPolicy {AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(30)};
cache.Add("PeopleData", peopleData, policy);
return peopleData;

如何在不同环境中部署后测试功能。

@MohamedSahir有两种

方法-

  1. 在 QA 环境中,您必须在主机服务器上具有某种日志记录机制,例如 Kibana 或普通日志文件生成。然后,借助适当的日志消息,您可以查看它是缓存命中还是未命中。

  2. 使用此处提到的性能计数器

最新更新