Yeah, the caching's not particularly ground-breaking, but the ease with which you can implement it is, especially when you realise that you don't need to have written the function you want to add caching to. You write one 15-line function, then you call it on any function you want to use caching and that's it. And you can only do that because you can treat functions as a kind of variable/class arrangement.
Prior to .NET 3.5, the asynchronous implementations of methods were prepended with Begin and End, so you'd have a Fetch function, plus a BeginFetch and an EndFetch. You got a specific return type from the Begin, then you'd call the End to get the actual return value.
In .NET 3.5, you have an implementation of the method ending in Async, plus an event which fires when it finishes executing that passes the return value (or the exception that occurred) in the event arguments. So you'd have FetchAsync and a FetchCompleted event.
So I've made a class where you pass in a function delegate (i.e. pointer) to the constructor, and it has a Completed event and an Invoke method and does basically the same thing but on any method.
Matt: once you get your mind round the basic concept, it's head-fuck free. Dance like it hurts; Love like you need the money; Work when people are watching. |