You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Commands: How to disable caching?

To disable caching in Commands use disableAllCaching method.

Syntax

public AutoCloseable disableAllCaching();

Return Value
AutoCloseable Method that will re-enable caching when disposed.

Example

store.getDatabaseCommands().put("employees/1", null, new RavenJObject(), new RavenJObject());
store.getDatabaseCommands().put("employees/2", null, new RavenJObject(), new RavenJObject());

store.getDatabaseCommands().get("employees/1"); // Response: '200 OK'
assertEquals(0, store.getJsonRequestFactory().getNumOfCachedRequests()); // not read from cache
assertEquals(1, store.getJsonRequestFactory().getCurrentCacheSize()); // employees/1 in cache

store.getDatabaseCommands().get("employees/1"); // Response: '304 Not Modified'
assertEquals(1, store.getJsonRequestFactory().getNumOfCachedRequests()); // read from cache
assertEquals(1, store.getJsonRequestFactory().getCurrentCacheSize()); // employees/1 in cache

store.getDatabaseCommands().get("employees/1"); // Response: '304 Not Modified'
assertEquals(2, store.getJsonRequestFactory().getNumOfCachedRequests()); // read from cache
assertEquals(1, store.getJsonRequestFactory().getCurrentCacheSize()); // employees/1 in cache

try (AutoCloseable disableCache = store.getDatabaseCommands().disableAllCaching()) {
  store.getDatabaseCommands().get("employees/2"); // Response: '200 OK'
  assertEquals(2, store.getJsonRequestFactory().getNumOfCachedRequests()); // not read from cache
  assertEquals(2, store.getJsonRequestFactory().getCurrentCacheSize()); // employees/1 and employees/2 in cache
  store.getDatabaseCommands().get("employees/2"); // Response: '200 OK'
  assertEquals(2, store.getJsonRequestFactory().getNumOfCachedRequests()); // not read from cache
  assertEquals(2, store.getJsonRequestFactory().getCurrentCacheSize()); // employees/1 and employees/2 in cache
}

store.getDatabaseCommands().get("employees/2"); // Response: '304 Not Modified'
assertEquals(3, store.getJsonRequestFactory().getNumOfCachedRequests()); // read from cache
assertEquals(2, store.getJsonRequestFactory().getCurrentCacheSize()); // employees/1 and employees/2 in cache