Add cache files function. Using mutex to protect last record. Has segment error inside now...