added reference counting to cache_files to properly reset them in case of pending requests that require them