Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPCache vs. HttpRuntime.Cache

I have a SharePoint 2010 Farm and want to use object caching for my own custom objects.

Since it's an ASP.net Application at it's core, I could use HttpRuntime.Cache. On the other hand, SharePoint 2010 offers it's own SPCache.

Why would I choose SPCache over the HttpRuntime.Cache one?

like image 413
Michael Stum Avatar asked Jan 23 '26 08:01

Michael Stum


2 Answers

FYI, I went with SPCache at the end. It is indeed a very unusual SharePoint class: Well documented, simple and straight-forward to use, painless to manage.

It does offer the one thing HttpRuntime.Cache does not do: Allowing me to create my own subcaches and invalidating this without wiping the entire HttpCache.

I could achieve the same using a Dictionary inside the HttpCache, but locking around that has some potential issues. I reflected on the SPCache and found a solid, thread safe implementation, so that's what I went with.

As a caveat: SPCache seems to be SharePoint Server only, not for Foundation.

like image 127
Michael Stum Avatar answered Jan 25 '26 23:01

Michael Stum


This question is intriguing.

  • Google returns no results for implementing SPCache
  • A search through unobfusticated code; reveals only two internal classes (DataCache and DBCache) in the User Profile system that use SPCache.

It sounds like you should not use SPCache (but usually the msdn page would say "not intended to be used by user code".)

like image 27
djeeg Avatar answered Jan 25 '26 23:01

djeeg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!