public class DatabaseCache extends Database
Database
implementation with a cache.Constructor and Description |
---|
DatabaseCache(Database database,
Cache<java.lang.String,java.lang.Object> cacheInstance)
Constructor which is designed to work with a variety of different caches.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<Response> |
bulk(java.util.List<?> list) |
boolean |
contains(java.lang.String id)
Checks if the cache contains the specified document.
|
<T> T |
find(java.lang.Class<T> classType,
java.lang.String id)
Preferentially use the cache for the find operation.
|
<T> T |
find(java.lang.Class<T> classType,
java.lang.String id,
Params params)
Preferentially use the cache for the find operation.
|
<T> T |
findAny(java.lang.Class<T> classType,
java.lang.String uri)
Preferentially use the cache for the find operation.
|
Cache<java.lang.String,java.lang.Object> |
getCache()
Returns the cache so that the application can manage it using the Cache
API methods.
|
Response |
post(java.lang.Object object) |
Response |
post(java.lang.Object object,
int writeQuorum) |
Response |
remove(java.lang.Object object) |
Response |
save(java.lang.Object object) |
Response |
save(java.lang.Object object,
int writeQuorum) |
Response |
update(java.lang.Object object) |
Response |
update(java.lang.Object object,
int writeQuorum) |
changes, createIndex, createIndex, deleteIndex, ensureFullCommit, find, find, find, findByIndex, findByIndex, getAllDocsRequestBuilder, getAttachment, getAttachment, getDBUri, getDesignDocumentManager, getPermissions, getShard, getShards, getViewRequestBuilder, info, invokeUpdateHandler, listIndices, remove, removeAttachment, removeAttachment, saveAttachment, saveAttachment, search, setPermissions
public DatabaseCache(Database database, Cache<java.lang.String,java.lang.Object> cacheInstance)
database
- non-null data structure with information about the database connectioncacheInstance
- non-null cache instance which has already been created and initializedpublic Cache<java.lang.String,java.lang.Object> getCache()
public <T> T find(java.lang.Class<T> classType, java.lang.String id)
Preferentially use the cache for the find operation. Adds the retrieved T to the cache if it was not present and was found in the remote database.
public <T> T find(java.lang.Class<T> classType, java.lang.String id, Params params)
Preferentially use the cache for the find operation. Adds the retrieved T to the cache if it was not present and was found in the remote database.
public <T> T findAny(java.lang.Class<T> classType, java.lang.String uri)
Preferentially use the cache for the find operation. Adds the retrieved T to the cache if it was not present and was found in the remote database.
Note that this method uses the URI as the cache key (and not document ID) since the
document may come from a different database or server. As a result even if the same object
is already stored in the cache under its document ID it would be retrieved remotely by
this method and re-stored in the cache with a URI key. This also prevents the remove
method from removing these objects from the cache so it is recommended to only use this
method with a CacheWithLifetimes
cache to avoid the cache growing unbounded.
public boolean contains(java.lang.String id)
Checks if the cache contains the specified document. If it does not then checks if the database contains the specified document.
public Response save(java.lang.Object object)
If the operation was successful then the object is also added to the cache.
public Response save(java.lang.Object object, int writeQuorum)
If the operation was successful then the object is also added to the cache.
public Response post(java.lang.Object object)
If the operation was successful then the object is also added to the cache.
public Response post(java.lang.Object object, int writeQuorum)
If the operation was successful then the object is also added to the cache.
public Response update(java.lang.Object object)
If the operation was successful then the object is also updated in the cache.
public Response update(java.lang.Object object, int writeQuorum)
If the operation was successful then the object is also updated in the cache.
public Response remove(java.lang.Object object)
If the operation was successful then the object is also removed from the cache.