Ready to Rock Software Development

Dealing with Data that Will Become Invalidated

Home  /  c#  /  Dealing with Data that Will Become Invalidated

Sharing is caring!

Having just read Eric Lippert’s excellent series on monads, I wanted to try it out for myself. It seemed like I had the perfect scenario.

I had the situation where I had to perform an expensive calculation on data that would eventually become invalidated. The problem came with notifying all classes which used that derived data that the base data had become invalid.

I saw two options:

  1. Raise an event on invalidation of the source and requiring all classes to listen and re-acquire the data 
  2. Find a mechanism by which classes could tell if their derived data was still valid 

The advantage of option 2 is that client classes would only need to re-acquire data when they needed it, not the instance it became invalid. The advantage of using a monad was that the invalidation logic could be accessed in the derived data, but also in any data that was subsequently derived from the derived data. And so I came up with and Invalidatable monad. I ended up not using it because it was overkill for the simple scenario I was trying to solve.

Leave a Reply

Your email address will not be published. Required fields are marked *