CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

SharePoint Part Caching (and RTFM)

Okay.  Like most sane people, I try to do most things without reading the manual first.  So, I'm happily developing my SharePoint Portal web parts, and I'm storing data into the PartCache, using the following method.  The method takes 4 values, Storage type, a cache key, the data, and a System.TimeSpan value, like so:

this.PartCacheWrite(Storage.Personal, "test", this.m_strvisibleCameras, new System.TimeSpan(30,0,0,0));

There are no overloads, so you have to pass the TimeSpan.  Well, of course I assumed that the System.TimeSpan value was the time to live for the cache object. Right?  That would make sense, if you've used other cached objects, like Page.Cache. But, I wanted the cache to live forever, so I went looking into the docs and guess what the TimeSpan is for? From the FM:

timeout   A System.TimeSpan that specifies the period during which PartCacheWrite attempts to write a value.

Okay.  Well, I'm SURE they had a great reason for requiring this value and not providing an overload.  But all my code was giving the WebPart 30 days to attempt to write a value.  Next time, I'll try to RTFM.

-Brendan



Comments

Brendan Tompkins said:

After more research, I've noticed that the above code DOES in fact set the time-to-live for the cache object. MS contradicts the sdk information here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnspts/html/sharepoint_amazonwebparts.asp" From this MS doc:

This is the code used to write to the cache (and to specify a 30-minute timeout period):

PartCacheWrite(Storage.None, cacheKeywordResult,
new KeywordResultCache(keywordReq, productInfo), new TimeSpan(0,30,0));

I've also noticed in my code that this TimeSpan value seems to both set the time-to-live AND the time-to-write. Possibly someone from MS can clairify this for us all.
# December 10, 2003 3:18 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!

Our Sponsors

Free Tech Publications