cloudhead/cradle — Issue #137: Each call to database() on a connection creates its own cache
Author: dobesv
Created: 2012-02-17 01:41:02+00:00
State: open

I was quite surprised to find that I was getting document conflicts with myself. It turned out that each call to conn.database("x") creates a new cache for objects from that database so you can save an object in one place but you will get a stale object back from another.

My workaround was to monkey-patch the database method so it returns the same database instance on subsequent calls. Perhaps the core code should do that as well?

However, I noticed that the cache will become problematic in the long term because there's no synchronization nor does the cache expire old entries. If I were to have multiple processes (say 2 servers or one server and one batch cron job) then I will risk conflicts.

Is the cache basically only suitable for use in single-process deployments?