开发者

C# Caching use of cache dependency

开发者 https://www.devze.com 2022-12-15 17:46 出处:网络
I am trying to implement caching in an web application. The caching is to be done in the BLL. The BLL method signiture is

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 obje开发者_Python百科ct, 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号