简体   繁体   中英

ObjectCache in .net Windows Applications

Is the ObjectCache class included in.Net Framework 3.5?

If not, is there an alternative for storing objects in cache, ( in windows applications not asp.net)?

And does anyone have any online resources or code snippets that demonstrate how to use the ObjectCache class?

Is the ObjectCache class included in .net framework 3.5

No.

You could still use the ASP.NET cache in a WinForms application if you reference the System.Web assembly:

HttpRuntime.Cache["key"] = "value";

and if you wanted to define more granular properties:

HttpRuntime.Cache.Add(
    "key",
    "value", 
    null,
    DateTime.MaxValue,
    TimeSpan.FromSeconds(3),
    CacheItemPriority.High,
    new CacheItemRemovedCallback(OnItemRemove)
);

ObjectCache is introduced in .NET framework 4. If you are using a prior framework, you can use Microsoft Entreprise Library caching .

I do not recommend you using HttpRuntime.Cache as it is not intended to be used outside of asp.net applications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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