so the factory reset solved your issue then? Try to pay attention this time about which apps you install so you can pinpoint it if the issue returns.
I don't really know how to explain cache on a technical level but sometimes parts of the cache get corrupt. This can especially happen after ota updates and will cause the device to run slow, cause force crashes, and in general just cause problems.
Wiping the cache can solve a lot of issues. It's a common thing for root users but i believe the stock nexus recovery offers the option.
If you access the bootloader (power off then hold volume down+power), then use the volume keys to navigate to the recovery option (press power to select) i think there's an option in there to wipe cache.
I'd verify but i don't have the stock recovery installed on my phone because i'm rooted.
Anyway, the cache does not contain data and it's its own partition. You can wipe it and it just rebuilds itself. You won't lose anything important wiping the cache.
Hopefully scary alien or someone can chime in that can explain cache in detail. Sorry, i just don't have that technical grasp on it to explain it properly.
As a more real world example, you're probably familiar with clearing the cache on your web browser on your pc..? That's basically the same type of deal.