Load and save cache

  1. when the program is fist lunch, it needs to load from other storage, example: redis、file、mysql…

  2. When the program crashes, the contents in the cache need to be stored in another store

I think may be add a hook to handle it

You probably should not rely on very complex things to happen 'on signal’s in your program, like flushing the whole cache over a network. You can look up patterns for ‘read through cache’ where everything will be synced in real time to a persistent db, that way a crash/exit is OK, but repeated access is done only in the memory cache.