C# 缓存使用缓存依赖

发布于 2024-08-16 17:26:03 字数 274 浏览 3 评论 0原文

我正在尝试在网络应用程序中实现缓存。缓存是在 BLL 中完成的。

BLL 方法签名

public static List<Ailias> Select(List<Filter> filters) 

目前只是调用 DAL 中的相应方法。

我遇到的问题是我的缓存依赖项是过滤器对象,每当过滤器对象不同时,就应该进行新的 DAL 调用。

我如何添加此依赖项,我在文档中所能找到的只是对文件的依赖项?

I am trying to implement caching in an web application. The caching is to be done in the BLL.

The BLL method signiture is

public static List<Ailias> Select(List<Filter> filters) 

and at the moment simply calls the corresponding method in the DAL.

The issue I'm having is my cache dependency will be the filters object, whenever the filters object differs, a new DAL call should be made.

How can i add this dependency, all I can find in the docs is a dependancy on a file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红尘作伴 2024-08-23 17:26:03

据我所知,有两个预定义的 CacheDependancies(文件和 Sql),但是没有什么可以阻止您实现自己的 CacheDependancy,如 在此链接中

There is, AFAIK two CacheDependancies pre-defined (File and Sql) however there is nothing to stop you implementing your own CacheDependancy as described in this link

我不在是我 2024-08-23 17:26:03

缓存依赖项只是从缓存中卸载项目的后台方法。这意味着将缓存管理逻辑放在另一个系统/进程中。它可以工作,但也会带来不必要的复杂性。

“...只要过滤器对象不同...”

与什么不同?该方法调用之前使用过什么吗?听起来你的列表集合是你的缓存键。

考虑在 List 集合上实现唯一的哈希键,并在缓存中维护两项 - 来自过滤器的具有静态名称(如“list-alias-filter-key”)的缓存键,以及 List 集合。

当您对该方法进行后续调用时,请将 List 唯一哈希键(缓存键)与“list-alias-filter-key”中的键进行比较。如果它们相同,您就知道可以安全地提取 List 的缓存值。如果它们不同,请使用新的 List 集合重新查询并重置缓存中的两个值。

Cache dependencies are simply a background method of unloading items from cache. It means putting cache management logic in another system/process. It can work, but it can also introduce more complexity than necessary.

"...whenever the filters object differs..."

Differs from what? Anything used previously in that method call? Sounds like your List collection is your cache key.

Consider implementing a unique hash key on the List collection, and maintain two items in your cache -- the cache key from your filter with a static name like "list-alias-filter-key", and the List collection.

When you make subsequent calls to the method, compare the List unique hash key (cache key) to the key in "list-alias-filter-key". If they're the same, you know you can safely pull the cached value for List. If they differ, requery using your new List collection and reset the two values in the cache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文