I have a view which returns a list of large Mongo Documents via an ORM (MongoEngine). The ORM query against the Collection varies on a number of levels (ordering, limit, offset, query filters, etc). However, the underlying data is not updated regularly.
To display the data, the view converts the Mongo Documents into Pythonic Dict objects.
For caching purposes, should I just call the built-in hash() function against the MongoEngine ORM method? In other words:
key = hash('Document.objects.filter(user_id__gt=5)')
value = Document.objects.filter(user_id__gt=5)
I would then use the Django caching API with a memcache backend.
This does not seem threadsafe but I’m not sure that’s a huge consideration. My bigger worry is the overhead of reading from/writing to Memcache for every query variation. I suppose I could just limit it to the most common queries.
I guess the biggest question is whether Mongo requires memcache at all for this sort of lower level functionality.
MongoDB uses memory mapped files and the underlying OS handles paging to/from disk vs. keeping data in memory as efficiently as it can. If you have extra RAM, use it for MongoDB to maximize your throughput and decrease your code complexity.