0

I have an event receiver that lsitenes on an "added" event. Inside that receiver I have to retrieve all contents of another list:

var refList=Web.Lists.TryGetList("ReferenceData");
var allItems=refList.GetItems();
foreach( var item in allItems) {
// stuff here
}

If I do this on the ItemAdded-Event each time I have to retrieve all data from the reference list. Because the data in the reference list does not change very often I would prefer to Cache the content and only refresh it once every day. Usually I would try HttpContext.Cache, but I do not seem to have a httpContext in an added receiver.

What is the best way to do this?

Ole Albers
  • 8,715
  • 10
  • 73
  • 166

1 Answers1

0

Did you try using System.Web.Caching and Cache the entire object that is returned? You can also set absolute expiration for the cache so that it expires 24 hrs from thee current Date-Time.
The best practices you should follow for Object Caching are mentioned here.

Vineet Desai
  • 872
  • 5
  • 16
  • Thx. But that is exactly the problem here. System.Web.Caching cannot be used directly. I need a HttpContext "somehwere" but there isn't any in this event receiver – Ole Albers Mar 14 '16 at 11:54
  • I think this post can you help you achieve this: http://stackoverflow.com/questions/1601352/how-to-obtain-the-httpcontext-in-event-handler – Vineet Desai Mar 14 '16 at 17:58