Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Webpart Caching - PartCacheWrite does not work

  Asked By: Jill    Date: Oct 12    Category: Sharepoint    Views: 1917

I tried using PartCacheWrite, PartCacheRead and PartCacheInvalidate to implement caching in my webpart. I was getting "Object reference not set to an instance of an object" error. I debugged the code to find that PartCacheWrite is not writing anything to the cache. Therefore PartCacheRead returns null.

Since I did not have much time at hand i went ahead and implemented caching using Page.Cache.

Any ideas on why it is failing? I checked the web.config and found that the Cache setting is set to use the CacheObject.

I would like to know how to use PartCache functions and why mine failed.



5 Answers Found

Answer #1    Answered By: Cassidy Sharpe     Answered On: Oct 12


Answer #2    Answered By: Damon Garner     Answered On: Oct 12

I dont think it is CAS. I have encapsulated my code  in a try catch block and it did not throw any exception.

PartCacheWrite(Shared, "Key", "Value", NoAbsoluteExpiration, System.TimeSpan.FromMinutes(10));
if(PartCacheRead(Shared, "Key") != null)
var = (ValueType)PartCacheRead(Shared, "Key");
dataGrid.DataSource = var;
catch(Exception ex)
lblError.Text = ex.Message;
lblError.Visible = true;

The if statement always returns  true. if it was CAS an SPException would have been thrown when i tried writing  to the Cache.

Answer #3    Answered By: Hans Weiss     Answered On: Oct 12

Have you tried constructing a timespan? Or using an absoluted expiration? It
may be instantly expiring.

Answer #4    Answered By: Alison West     Answered On: Oct 12

There is no AbsoluteExpiration and SlidingExpiration in PartCacheRead. The code  was not accessible while sending that mail and i wrote from memory. Got confused between the syntax of PartCacheWrite and Page.Cache.Insert

PartCache takes only one TimeSpan parameter at the very end. It is the timeout setting  for writing  the value to cache. No info is available if that also doubles as the Expiration setting.

Anyway I tried constructing a new TimeSpan object  and TimeSpan.FromMinutes, there was no difference.

Answer #5    Answered By: Freddy Heath     Answered On: Oct 12

Do you have the actual code  you’re using? Can you post that?

Didn't find what you were looking for? Find more on Webpart Caching - PartCacheWrite does not work Or get search suggestion and latest updates.