简体   繁体   English

使用泛型的聪明缓存?

[英]Clever caching using generics?

Are there any clever layers out there to sit on top of the System.Web.Caching.Cache class to handle simple scenarios to fetch items using generics. 是否有任何聪明的层位于System.Web.Caching.Cache类的顶部,以处理简单的场景以使用泛型来获取项目。

I'd like to maybe provide a delegate function to retrieve an item, and be able to fetch an item with a strongly typed GetItem and a delegate function to retrieve an item if it isnt found. 我可能想提供一个委托函数来检索项目,并能够使用强类型的GetItem来获取项目,并且如果没有找到,则可以使用委托函数来检索项目。

For instance 例如

 CleverCache<K, T> 
 T GetItem(K)

 RegisterDelegate(FetchItemDelegate<K,T>)

I'd also like a nice way to handle a cache that only ever handles a single object. 我还希望有一种很好的方式来处理仅处理单个对象的缓存。

The ASP.NET Cache object just seems really primitive. ASP.NET Cache对象似乎真的很原始。 It just seems like a hashtable with a timeout. 看起来就像是带有超时的哈希表。 They may as well just call it HashtableWithTimeout for all I care. 就我所关心的而言,他们也可以将其称为HashtableWithTimeout。 I want some better astraction. 我想要更好的吸引力。 Is this the kind of thing that the caching application block will do for me? 缓存应用程序块会为我做这种事情吗?

Yes I know this is fairly simple code, i just dont have time for any wheel reinventing right now. 是的,我知道这是相当简单的代码,我现在没有时间重新发明轮子。

You may want to look into some more sophisticated cache providers that can wrap the ASP.NET cache, such as the Enterprise Library 's caching block. 您可能需要研究一些可以包装ASP.NET缓存的更复杂的缓存提供程序,例如企业库的缓存块。 It provides a much more robust and rich caching story for object lifecycle, invalidation, retrieval, etc. 它为对象生命周期,失效,检索等提供了更加健壮和丰富的缓存故事。

The ASP.NET cache deserves more credit than you give it - it's actually a very powerful base. ASP.NET缓存值得您付出的功劳-实际上,这是一个非常强大的基础。 Alone, it doesn't do anything complex as you have pointed out, but it is well-designed and robust enough to support some pretty cool stuff. 正如您所指出的那样,它本身并没有做任何复杂的事情,但它的设计合理且强大,足以支持一些非常酷的东西。

You may want to look into SharedCache and Microsoft Velocity as improvements to the basic caching available in ASP.NET. 您可能希望研究SharedCacheMicrosoft Velocity,以改进ASP.NET中可用的基本缓存。 I don't know how extensively strong typing is designed into either - but from the samples and documentation I've seen it's better than the ASP.NET Cache. 我不知道在其中设计了广泛的强类型-但是从示例和文档中,我发现它比ASP.NET Cache更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM