nathanchere
nathanchere

Reputation: 8098

RavenDB - caching? "Staleness"? Why are updated documents not being returned with the updates?

I'm trying to convert my own blog from MSSQL/EF to RavenDB and for the most part it has been pretty painless so far, but I'm having an issue with what I suspect is either 'stale indexes' or overly assertive caching, but I can't get any actual answers. It's easier to demonstrate than explain when I don't know what the actual problem is.

The setup:

// Basic example class
public class ExampleClass{
    public int ID {get;set;}
    public string Value {get;set;}
}

// Once at application startup:
_docStore = new DocumentStore {
    Url = "http://localhost:8080",
    DefaultDatabase = "exampleDB",
    Credentials = new NetworkCredential("userfoo","passbar"),
    };            
_docStore.Initialize();

// Querying data:    
using (var session = _docStore.OpenSession())
{
    var results = _session.Query<ExampleClass>().ToList();        
    foreach(var result in results)
    {
        Console.WriteLine(string.Format("ID #{0}: {1}",
          result.ID, result.Value));
    }
}

The problem is: Whenever I update documents programmatically through a session of _docStore everything works fine. When I edit data externally (from another client, in RavenDB management studio etc) document updates aren't being returned. Where's some examples.


1) Initial values in database

Documents in the database:

Run query; console result:


2) After update ExampleClass/2 value to "BAR" through _docStore session.

Documents in the database:

Run query; console result:


3) After update ExampleClass/2 value to "bah" through RavenDB studio

Documents in the database:

Run query; console result:


4) After add ExampleClass/3 through RavenDB studio

Documents in the database:

Run query; console result:


5) After delete ExampleClass/2 through RavenDB studio

Documents in the database:

Run query; console result:


6) After change ExampleClass/3 value through RavenDB studio

Documents in the database:

Run query; console result:


6) After add ExampleClass/4 through RavenDB studio

Documents in the database:

Run query; console result:


*7) After initialise new DocumentStore (no data changes) *

Documents in the database:

Run query; console result:


Hopefully that shows well enough where things are going wrong. Adding and removing entire documents is reflected fine but updates are completely ignored beyond the first load, which is what made me suspect caching rather than a 'stale index'... but I have tried things like this with no luck:

// After initialising document store:
_docStore.DisableAggressiveCaching();
_docStore.DatabaseCommands.DisableAllCaching();
_docStore.Conventions.DefaultQueryingConsistency =
  ConsistencyOptions.QueryYourWrites;

// Whenever opening a new session:
_session.Advanced.DatabaseCommands.DisableAllCaching();
_session.Advanced.AllowNonAuthoritativeInformation = false;                

// When querying:
var result = _session.Query<ExampleClass>()
  .Customize(x=>x.WaitForNonStaleResults())
  .ToList();

What the !$#* is going on? Why does RavenDB hate me?

Upvotes: 1

Views: 917

Answers (2)

Ayende Rahien
Ayende Rahien

Reputation: 22956

RavenDB is doing caching, but it is doing so by checking the etag, so you shouldn't be seeing this. Is it possible that you are always using a single session?

Can you try to create a reproduction of this?

Upvotes: 2

nathanchere
nathanchere

Reputation: 8098

It looks like the same session is always being returned by docStore.OpenSession() which matches Oren's suggestion. Using the current (1.0.701) RavenDB libraries resolved the issue.

Upvotes: 0

Related Questions