Caching implementation reduced in size by using closures for the update
functions.