Accessing Cache in a SharePoint List Item event Receiver

There are times when for performance reasons you might want to store things in the Application cache. The same applies to SharePoint also.

In our recent project we had to store some configuration information in a SharePoint list that would rarely change. So instead of reading it from the SP list every time we decided to store it in the Cache. This was easy to do as we did it inside a web part. And since we can hook up to the List modifications through Event Receivers we planned to clear the cache in the event code.

But what we dint realize was that there was no easy way to get to the application cache L inside the event receiver code. SPContext is null.

So what do you do ? After some research I found out that you can access the cache through HttpRuntime.Cache. Also removing a cache value through cache["Key"] will throw an exception. You would have to say cache.Remove("Key")

 

HTH

Hari

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.