Add support for validity set by callback function.

See digitalcreations/cache#1.