如何从内存中释放对象

时间:2022-08-28 17:18:39

I have this generic list that is being cached in memory. How can I manually during testing release that object from the cache? I cleared cache on the browser but still when I refresh I get the same set of products becuase it's checking my cached object in my database retrieval method.

我有这个通用列表缓存在内存中。如何在测试期间手动从缓存中释放该对象?我清除了浏览器上的缓存,但是当我刷新时,我得到相同的产品集,因为它在我的数据库检索方法中检查我的缓存对象。

4 个解决方案

#1


0  

coffeeaddict you need to implement cache expiration and removal in order for your app to use updated data. If you're using your own caching implementation make sure you invalidate that cached data every time you update the persistent one, so the next time you request it it'll go up full path and cache it in-memory again.

coffeeaddict您需要实现缓存过期和删除,以便您的应用程序使用更新的数据。如果您正在使用自己的缓存实现,请确保每次更新持久数据时都会使缓存的数据无效,因此下次您请求它时,它将上升到完整路径并再次将其缓存在内存中。

#2


3  

You are confusing the browser's cache (on the client machine) with server-side caching.

您将浏览器的缓存(在客户端计算机上)与服务器端缓存混淆。

#3


2  

Try Cache.Remove() method to remove an object from ASP.NET cache :

尝试使用Cache.Remove()方法从ASP.NET缓存中删除对象:

Cache.Remove("CacheKey");

Because the cached items are saved in server's memory, you can't clear application cache by clearing browser cache.

由于缓存的项目保存在服务器的内存中,因此无法通过清除浏览器缓存来清除应用程序缓存。

#4


0  

Your database retrieval method is running on the server, which has nothing to do with your browser cache (which is why clearing your browser cache won't do anything).

您的数据库检索方法正在服务器上运行,这与您的浏览器缓存无关(这就是为什么清除浏览器缓存不会做任何事情)。

Your question isn't too clear, but I'm assuming that you're using the ASP.Net Cache object for your caching.

您的问题不太清楚,但我假设您正在使用ASP.Net Cache对象进行缓存。

You'll need to add some code to your database retrieval method to refresh the item in the ASP.net cache. It would help if you could post the code that you have, but basically it would look like:

您需要在数据库检索方法中添加一些代码来刷新ASP.net缓存中的项目。如果您可以发布您拥有的代码,这将有所帮助,但基本上它看起来像:

var data = DatabaseFetchStuff....
Cache["databaseInfoKey"] = data;

#1


0  

coffeeaddict you need to implement cache expiration and removal in order for your app to use updated data. If you're using your own caching implementation make sure you invalidate that cached data every time you update the persistent one, so the next time you request it it'll go up full path and cache it in-memory again.

coffeeaddict您需要实现缓存过期和删除,以便您的应用程序使用更新的数据。如果您正在使用自己的缓存实现,请确保每次更新持久数据时都会使缓存的数据无效,因此下次您请求它时,它将上升到完整路径并再次将其缓存在内存中。

#2


3  

You are confusing the browser's cache (on the client machine) with server-side caching.

您将浏览器的缓存(在客户端计算机上)与服务器端缓存混淆。

#3


2  

Try Cache.Remove() method to remove an object from ASP.NET cache :

尝试使用Cache.Remove()方法从ASP.NET缓存中删除对象:

Cache.Remove("CacheKey");

Because the cached items are saved in server's memory, you can't clear application cache by clearing browser cache.

由于缓存的项目保存在服务器的内存中,因此无法通过清除浏览器缓存来清除应用程序缓存。

#4


0  

Your database retrieval method is running on the server, which has nothing to do with your browser cache (which is why clearing your browser cache won't do anything).

您的数据库检索方法正在服务器上运行,这与您的浏览器缓存无关(这就是为什么清除浏览器缓存不会做任何事情)。

Your question isn't too clear, but I'm assuming that you're using the ASP.Net Cache object for your caching.

您的问题不太清楚,但我假设您正在使用ASP.Net Cache对象进行缓存。

You'll need to add some code to your database retrieval method to refresh the item in the ASP.net cache. It would help if you could post the code that you have, but basically it would look like:

您需要在数据库检索方法中添加一些代码来刷新ASP.net缓存中的项目。如果您可以发布您拥有的代码,这将有所帮助,但基本上它看起来像:

var data = DatabaseFetchStuff....
Cache["databaseInfoKey"] = data;