如何清除ASP.NET Core中的MemoryCache? [英] How to clear MemoryCache in ASP.NET Core?

查看:276
本文介绍了如何清除ASP.NET Core中的MemoryCache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从ASP.NET Core正确清除IMemoryCache?

How to correctly clear IMemoryCache from ASP.NET Core?

我相信此类缺少Clear方法,但是无论如何该如何处理?在我的项目中,我将DocumentRepository的方法缓存了24小时,从数据库中获得了很多行.但是有时候我可以更改数据库,所以我想清除IMemoryCache,因为它有垃圾数据.

I believe this class is missing Clear method, but anyway how to deal with it? In my project I'm caching DocumentRepository's methods for 24 hours where I'm getting lots of rows from database. But sometimes I can change the database, so I want to clear the IMemoryCache as it has got rubbish data.

推荐答案

要清除您的MemoryCache,只需按键删除您的内存缓存,就像这样:

To clear you MemoryCache, just remove your memory cache by key, like this:

memoryCache.Remove("your_key");

这篇关于如何清除ASP.NET Core中的MemoryCache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆