Cache: implement "dirty" attribute to only re-serialize when necessary