Write cache function