I need an advice where to cache the stock ticker info that i pull from a 3rd party service. The requirement is that if the ticker info is unavailable, i have to cache the last positive result set and use that as a view model to display inside the web part. Main point here is that caching has to be not just at iis process level but rather distributed across all nodes.

Using a whole list seems like an overkill while caching into the SPWeb.AllProperties is a bit awkward as pulling the latest available value is hard to do.

Any thoughts out there?

  • How big is the data? Is it stored in a custom in memory object? – Amal Hashim Oct 28 '14 at 22:47
  • it's only a few data points,about 8. My thought is just to serilize/deserialize using json real quick. That's why i think building a whole list for it is way too much – Roman Oct 28 '14 at 22:49

The best bet is to use SPWeb property bag. This caches the data and shared across the farm and will persist through server reboots.

For adding a new property you can use following code block

    //GET SPWEB...

    // unsafe updates are required to be able to write to the property bag
    spWeb.AllowUnsafeUpdates = true;

    // you must check to see if the collection has a value in the assigned key already
    if (!spWeb.AllProperties.ContainsKey(key))
        spWeb.Properties.Add(key, myValue);
        spWeb.AllProperties[key] = myValue;

    // update the properties
    spWeb.AllowUnsafeUpdates = false;

To read a property you can use following.

if (currentSite.AllProperties.ContainsKey("MyItem"))
    myItem = currentSite.AllProperties["MyItem"].ToString();

In your specific case cache the ticker information on first load. Keep a KEY property which can be compared to take a decision whether to update the already cached data or not.

  • i was considering this approach as well and it should work ok as i require eventual consistency semantics. The only thing that threw me off was that when i reviewed how the object model actually persists the data through dotPeek there is a lot of extra overhead. I think i'll go with this approach. – Roman Oct 28 '14 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.