Couchbase .Net client library GetView caching issue
Tue, 07/03/2012 - 07:17
I'm running couchbase server 2.0 (dev preview 4) and using .net client library version 1.2.
When I add some document (json) to my database and then in few seconds (less then 10) I try to get this document via GetView through .net client library and it always returns old value on first query. Only on second query it returns actual value.
When I exec same query through REST api, it returns actual value.
Can anyone provide some information about this?
I'm guessing this was also your question? http://stackoverflow.com/questions/11296815/couchbase-net-client-library...
Copying my SO answer below. Let me know if you need any other help...
The default behavior of views in Couchbase is to update the index for a view incrementally. It's requesting a view that actually triggers the incremental update. In other words, when you requested the view the first time, you triggered the index to be updated on the server (only new documents need to be indexed). So the new document(s) was indexed by the time you made the second call to GetVew.
In this way, Couchbase views are eventually consistent. If a stale read is not appropriate or tolerable for your situation, you could use the Stale fluent method when you request the view and modify the default behavior.
So to force the view to be updated before getting results:
var view = client.GetView("beers", "by_name").Stale(StaleMode.False);
Some more info is available at http://www.couchbase.com/docs/couchbase-sdk-net-1.2/api-reference-view.html.
-- John