I want to save and download the record ID last inserted into the database, and read it again when the download method is called. After inserting, the original record ID is overwritten. How to achieve better performance? Save to database? Save to file? Will the cache be flushed?
为情所困2017-05-16 13:14:21
If there is redis
或者memcache
作为缓存的话设置key
永不过期可以解决(redis
可持久化数据,但不排除宕机后丢失),每次插入后更新值,相对性能较好,保存数据库和文件也可以解决问题,也可以两者同时使用,既保存到数据库又放入缓存,更新时增加成本但可靠性更好,也可以换种思路,每次去数据库查询,对于innodb
引擎的mysql
数据表,主键查询效率较高,id
It is also a good solution to take the first one in reverse order. If a connection pool is used, the performance will be better.