C# 缓存使用缓存依赖
我正在尝试在网络应用程序中实现缓存。缓存是在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,有两个预定义的 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
缓存依赖项只是从缓存中卸载项目的后台方法。这意味着将缓存管理逻辑放在另一个系统/进程中。它可以工作,但也会带来不必要的复杂性。
“...只要过滤器对象不同...”
与什么不同?该方法调用之前使用过什么吗?听起来你的列表集合是你的缓存键。
考虑在 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.