search

Home  >  Q&A  >  body text

memcached - 使用mongodb搭配memcache

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

PHPzPHPz2764 days ago817

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-24 16:01:35

    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)

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-04-24 16:01:35

    "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.

    reply
    0
  • 高洛峰

    高洛峰2017-04-24 16:01:35

    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?

    reply
    0
  • Cancelreply