add write-to-file functions for caching