如何远程清除缓存?

编程入门 行业动态 更新时间:2024-10-21 23:04:31
本文介绍了如何远程清除缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

场景:我有一个存储在内存缓存中的对象(来自DB的结果集)(cache.Add(key,object))。此缓存具有绝对过期作为缓存策略。有时我需要在到期之前清除缓存中的对象(cache.Remove(key))。我的应用程序在IIS上运行,永远不会停止。 问题:所以我的问题是如何使用单独的应用程序实现这一目标?或者是否还有其他方法可以在缓存达到绝对到期之前清除缓存?

Scenario : I have an object (result set from DB) stored in memory cache (cache.Add(key, object)). This cache is having absolute expiration as cache policy. Some times I need to clear the object in cache (cache.Remove(key)) before the expiration. My application is running on IIS which should never be stopped. Question: So my question is how can I achieve this using a separate application ? Or is there any other way to clear cache before it reaches the absolute expiration ?

推荐答案

当您使用ASP.NET时,您可能需要创建一个按钮和/或者将执行此操作的页面,这将触发ASP.NET服务器上的代码以调用cache.Remove(key)。 假设清除缓存是某种东西你不希望普通用户这样做,最好的方法是将页面/按钮放在他们无法访问的地方,或隐藏普通用户。 如果你使用webforms,也许在你的页面上创建一个按钮,当点击它时执行cache.Remove调用,并且只有在你登录时才将可见性设置为true。 如果使用MVC,可能是一个调用控制器上调用cache.Remove的方法的链接 As you're using ASP.NET you probably need to create a button and/or page that will do this, and this will trigger the code on your ASP.NET server to call cache.Remove(key). Assuming clearing the cache is something you don't want normal users to do, the best approach is to put the page/button somewhere they cannot access it, or hide from normal users. If you're using webforms, perhaps create a button on your page that when clicked performs the cache.Remove call, and set visibility to true only if it's you logged in. If using MVC, perhaps a link that calls a method on the controller which calls cache.Remove

更多推荐

如何远程清除缓存?

本文发布于:2023-11-26 03:01:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632373.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!