Use mongodb with memcache

  mongodb, question

The website is expected to have a large number of queries, compared with writing to the database.
What I want to do is to divide the contents of the database into two types, one is the contents for indexing, which contain index items corresponding to various required information, and the other is the specific data contents to be queried.
Firstly, the specific content is stored in memcache, and the corresponding data is obtained from memcache through the index value obtained from the database during query.
When writing data, it is directly written into mongodb;
Don’t know what’s wrong with this kind of practice, come here to seek advice ~ ~

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

  1. Since mongodb is selected, you should try your best to use a key to obtain the data of the entire document in this query scenario. This kind of query is mongodb’s best, and theoretically there is no need to make any further optimization.
  2. If you have multiple queries to get the desired results in addition to the above situation, you can consider using cache. Now it feels that using Redis is more flexible than Memcached. Specifically, the processing steps are as follows:
    (1) Each query first goes to the cache to find out whether there is already a value
    (2) If not, it is to use your query criteria as key and the query results as value according to certain rules, store them in cache and return the query results this time.
    (3) Return directly if there is one (cache invalidation control should be done according to business requirements, such as valid duration or new writes)