memcached - 使用mongodb搭配memcache
PHPz
PHPz 2017-04-24 15:59:35
0
3
842

网站预计会有很大的查询量,相比之下写入数据库的操作要少很多。
我想的是把数据库内容分成两种,一种是用于索引的内容,内容包含各种所需信息对应的索引项,另一种是其他所要查询的具体数据内容。
先将具体内容存入memcache,查询时通过从数据库中得到的索引值再从memcache中取得对应数据;
写入数据时则直接写到mongodb中;
不知道这种做法有什么不妥,来这寻求下建议~~

PHPz
PHPz

学习是最好的投资!

reply all(3)
Peter_Zhu

This is a typical caching usage scenario. Based on the technical solution you use, there are several points that need to be considered clearly:

  1. Since you choose mongodb, your query scenario should try to use one key to obtain the data of the entire document. This kind of query is what mongodb is best at, and theoretically no further optimization is needed.
  2. If in addition to the above situation, you have to query multiple times to get the desired results, you can consider using cache. Now I feel that using Redis is more flexible than Memcached. More specific steps:
    (1) For each query, first go to the cache to see if there is already a value
    (2) If not, use your query conditions as the key according to certain rules, the query results as the value, store them in the cache and return the results of this query.
    (3) If there is, return it directly (according to business needs, cache invalidation control must also be done, such as the validity period or new writes)
我想大声告诉你

"First store the specific content in memcache, and then obtain the corresponding data from memcache through the index value obtained from the database during query;" I don't quite understand this sentence. Should the data be saved in the cache? If the downtime data is not It’s gone.

小葫芦

I don’t know how much business the poster has. Mongodb is a hybrid database. Even Mongodb also has an in-memory database part. Mongodb is not a bad writing bottleneck, so the reading business should be placed in a pure in-memory database like redis. For business, there is no need to go through the trouble. Wouldn’t it be better to save it directly in mongo?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template