add write to cache and associated tests