[译]Ocelot - Caching

时间:2023-03-09 23:09:18
[译]Ocelot - Caching

原文

Ocelot支持基本的缓存,目前Ocelot的缓存是通过CacheManager project实现的。

下面的示例展示了如何启用缓存:

s.AddOcelot()
.AddCacheManager(x =>
{
x.WithDictionaryHandle();
})

为了在路由中使用缓存,需要在ReRoute中添加下面的配置:

"FileCacheOptions": { "TtlSeconds": 15, "Region": "somename" }

上面的例子中TtlSeconds设置缓存会在15秒中后失效。

Ocelot目前支持对下游服务的url进行缓存,通过TtlSeconds设置缓存过期时间。可以通过Ocelot的administration API清除缓存。