开发者

Is it practical to use Mongo's capped collection a memory cache?

开发者 https://www.devze.com 2023-04-09 10:10 出处:网络
Is it practical to use Mongo\'开发者_运维问答s capped collections as poor man\'s memcache assuming it will be kept in memory most of the time?You can definitely use capped collections for this purpose

Is it practical to use Mongo'开发者_运维问答s capped collections as poor man's memcache assuming it will be kept in memory most of the time?


You can definitely use capped collections for this purpose. But it's important to know the basic limitations.

  1. Data will expire based on insert order not time-to-expire
  2. Data that is frequently accessed may still be pushed out of memory
  3. _id columns are not defined on Capped Collections by default, you will need to ensure those indexes.
  4. The objects cannot be modified in a way that changes the size of the object. For example, you could increment an existing integer, but you cannot add a field or modify a string value on the entry.
  5. The capped collections cannot be sharded.

Because of #1 & #4 & #5, you are definitely losing some the core Memcache functionality.

There is a long-outstanding JIRA ticket for TTL-based capped collections which is probably exactly what you want.

Of course, the big question in this whole debate is "where is the extra RAM". Many people who use MongoDB as their primary store simply drop Memcache. If you have a bunch of extra RAM sitting around, why not just use it store the actual data instead of copies of that data?


Yes. This is a perfectly acceptable use of a MongoDB capped collection. I am assuming you will have many more reads than writes, so make sure you use an index as well.

MongoDB Capped Collections: Applications


As said by Gates VP, capped collections are usable and easy to manage. However you can also use non-capped collections if you :

  • have a dedicated server for your "poor's man memcache"
  • have a lot of data, which cannot fit on one server (or you want to query very fast)
  • are ok with dealing with TTL yourself (just add one field)

MongoDB cache (mmap on Unix-like systems) will provides a "unlimited" memcache, caching frequently accessed values. As said on the mongo FAQ page :

The goal is for Mongo to be an alternative to an ORM/memcached/mysql stack

0

精彩评论

暂无评论...
验证码 换一张
取 消