My apps can't save my input or choice in android 6.0.1, how to fix it?
It's not the answer you were looking for but what I would do if I were in your shoes would be to install the latest TWRP (assuming you rooted) and download the latest "hammerhead" for Nexus 5 (GSM/LTE) 6.0.1 (M4B30X, Oct 2016).

After you get the .zip, unpack it to a folder. You'll see 


bootloader-hammerhead-hhz20h.img
radio-hammerhead-m8974a-2.0.50.2.30.img
image-hammerhead-m4b30x.zip
flast-all.bat


Unpack that enclosed zip as well to get:


boot.img
cache.img
system.img
userdata.img
recovery.img


Edit flash-all.bat to something like this:

@ECHO OFF

::PATH=%PATH%;"%SYSTEMROOT%\System32"
fastboot flash bootloader bootloader-hammerhead-hhz20h.img
fastboot reboot-bootloader
ping -n 5 127.0.0.1 &gt;nul
fastboot flash radio radio-hammerhead-m8974a-2.0.50.2.30.img
fastboot reboot-bootloader
ping -n 5 127.0.0.1 &gt;nul

fastboot erase boot
fastboot flash boot boot.img

fastboot erase cache
fastboot flash cache cache.img

fastboot erase system
fastboot flash system system.img

fastboot erase userdata
fastboot flash userdata userdata.img

::fastboot flash recovery twrp.img     // this one if rooted
::fastboot flash recovery recovery.img // this one if not rooted

echo Press any key to exit...


You mentioned you flashed a factory image before so I ommited the information about how to set up and use fastboot.exe but the details can be found here: https://developers.google.com/android/images

I don't know that this will fix your cache issue but it is a more complete flash method than running the stock flash-all.bat.