initial attempt at a proper generic memoizer