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?
Capped collection in MongoDB supports high-throughput operations used for insertion and retrieval of documents based on the order of insertion. Capped collection working is similar to circular buffers, i.e., there is a fixed space allocated for the capped collection.
capped: It is used to create a capped collection. If the value of this field is true then you must specify the maximum size in the size field. It is of boolean type.
Explanation: Use the isCapped() method to determine if a collection is capped, as: db. collection. isCapped().
You can definitely use capped collections for this purpose. But it's important to know the basic limitations.
_id
columns are not defined on Capped Collections by default, you will need to ensure those indexes.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With