Package com.googlecode.objectify.cache
Class CachingAsyncTransaction
- java.lang.Object
-
- com.googlecode.objectify.cache.CachingAsyncDatastoreReaderWriter
-
- com.googlecode.objectify.cache.CachingAsyncTransaction
-
- All Implemented Interfaces:
AsyncDatastoreReaderWriter
,AsyncTransaction
,PrivateAsyncTransaction
public class CachingAsyncTransaction extends CachingAsyncDatastoreReaderWriter implements PrivateAsyncTransaction
A write-through memcache for Entity objects that works for both transactional and nontransactional sessions.
- Caches negative results as well as positive results.
- Queries do not affect the cache in any way.
- Transactional reads bypass the cache, but successful transaction commits will update the cache.
- This cache has near-transactional integrity. As long as DeadlineExceededException is not hit, cache should not go out of sync even under heavy contention.
Note: Until Google adds a hook that lets us wrap native Future> implementations, you muse install the
AsyncCacheFilter
to use this cache asynchronously. This is not necessary for synchronous use ofCachingDatastoreService
, but asynchronous operation requires an extra hook for the end of a request when fired-and-forgotten put()s and delete()s get processed. If you use this cache asynchronously, and you do not use theAsyncCacheFilter
, your cache will go out of sync.- Author:
- Jeff Schnitzer
-
-
Constructor Summary
Constructors Constructor Description CachingAsyncTransaction(AsyncTransaction raw, EntityMemcache memcache)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.cloud.datastore.Transaction.Response
commit()
Future<Void>
delete(Iterable<com.google.cloud.datastore.Key> keys)
protected void
empty(Iterable<com.google.cloud.datastore.Key> keys)
void
enlist(Result<?> result)
Future<Map<com.google.cloud.datastore.Key,com.google.cloud.datastore.Entity>>
get(Collection<com.google.cloud.datastore.Key> keys, com.google.cloud.datastore.ReadOption... options)
com.google.protobuf.ByteString
getTransactionHandle()
boolean
isActive()
void
listenForCommit(Runnable listener)
Future<List<com.google.cloud.datastore.Key>>
put(Iterable<? extends com.google.cloud.datastore.FullEntity<?>> entities)
void
rollback()
<T> com.google.cloud.datastore.QueryResults<T>
run(com.google.cloud.datastore.Query<T> query)
void
runCommitListeners()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.googlecode.objectify.impl.AsyncDatastoreReaderWriter
get, put
-
-
-
-
Constructor Detail
-
CachingAsyncTransaction
public CachingAsyncTransaction(AsyncTransaction raw, EntityMemcache memcache)
-
-
Method Detail
-
empty
protected void empty(Iterable<com.google.cloud.datastore.Key> keys)
- Specified by:
empty
in classCachingAsyncDatastoreReaderWriter
-
commit
public com.google.cloud.datastore.Transaction.Response commit()
- Specified by:
commit
in interfaceAsyncTransaction
-
isActive
public boolean isActive()
- Specified by:
isActive
in interfaceAsyncTransaction
-
rollback
public void rollback()
- Specified by:
rollback
in interfaceAsyncTransaction
-
listenForCommit
public void listenForCommit(Runnable listener)
- Specified by:
listenForCommit
in interfaceAsyncTransaction
-
getTransactionHandle
public com.google.protobuf.ByteString getTransactionHandle()
- Specified by:
getTransactionHandle
in interfaceAsyncTransaction
-
runCommitListeners
public void runCommitListeners()
- Specified by:
runCommitListeners
in interfacePrivateAsyncTransaction
-
enlist
public void enlist(Result<?> result)
- Specified by:
enlist
in interfacePrivateAsyncTransaction
-
delete
public Future<Void> delete(Iterable<com.google.cloud.datastore.Key> keys)
- Specified by:
delete
in interfaceAsyncDatastoreReaderWriter
- Overrides:
delete
in classCachingAsyncDatastoreReaderWriter
-
get
public Future<Map<com.google.cloud.datastore.Key,com.google.cloud.datastore.Entity>> get(Collection<com.google.cloud.datastore.Key> keys, com.google.cloud.datastore.ReadOption... options)
- Specified by:
get
in interfaceAsyncDatastoreReaderWriter
-
run
public <T> com.google.cloud.datastore.QueryResults<T> run(com.google.cloud.datastore.Query<T> query)
- Specified by:
run
in interfaceAsyncDatastoreReaderWriter
- Overrides:
run
in classCachingAsyncDatastoreReaderWriter
-
put
public Future<List<com.google.cloud.datastore.Key>> put(Iterable<? extends com.google.cloud.datastore.FullEntity<?>> entities)
- Specified by:
put
in interfaceAsyncDatastoreReaderWriter
- Overrides:
put
in classCachingAsyncDatastoreReaderWriter
-
-