cloudhead/cradle — Issue #145: Cache never expires.
Author: mintplant
Created: 2012-02-24 05:10:24+00:00
State: open

There doesn't currently appear to be any mechanism that expires documents loaded into the cache. Because of this, two problems can result:

1) The underlying database is modified by another application, for example, another instance of the program, say in a load-balancing setup, or by the database administrator via Futon.
2) Documents accumulate in the cache until, theoretically, the entire database could end up in memory.

Problem 1 could be solved, at least for the multiple-running-instances situation, by allowing for an external, shared data store to hold the cache data. That wouldn't really fix everything, though.

Another option could be to save the Etags returned by CouchDB in requests. When a document is retrieved, a request could be made to the database to check if the cached version corresponding to the Etag is still fresh. If Couch returns "Not Modified", then serve up the cached version; else, return whatever Couch sends back, and update the version in the cache. This doesn't prevent the accumulation issue, though.