关于数据写入缓存设计

WBOY
Release: 2016-06-06 20:43:19
Original
979 people have browsed it

比如说文章的浏览数会根据每一次访问而递增,每次都写入的话影响性能,单纯memcache数据可能丢失。利用mysql,和memcache,我琢磨着每次写入读取都在memcache,mysql上建一个记录表保存需要缓存的表名及字段信息,在每隔5分钟执行计划任务,读取记录表对应着将memcache缓存持久化到mysql相应表。感觉设计的很蹩脚,大家这一类写入缓存是怎么设计的?

回复内容:

比如说文章的浏览数会根据每一次访问而递增,每次都写入的话影响性能,单纯memcache数据可能丢失。利用mysql,和memcache,我琢磨着每次写入读取都在memcache,mysql上建一个记录表保存需要缓存的表名及字段信息,在每隔5分钟执行计划任务,读取记录表对应着将memcache缓存持久化到mysql相应表。感觉设计的很蹩脚,大家这一类写入缓存是怎么设计的?

用redis来代替memcache就可以了,计数器都写到redis里面去

<code>if($memcache->inc()/100 == 0){
     $mysql->write();
}
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template