View source on GitHub |
Inherits From: expected_type
google.appengine.ext.ndb.Context(
conn=None,
auto_batcher_class=google.appengine.ext.ndb.AutoBatcher
,
config=None,
parent_context=None
)
Methods
allocate_ids
allocate_ids(
key, size=None, max=None, **ctx_options
)
call_on_commit
call_on_commit(
callback
)
Call a callback upon successful commit of a transaction.
If not in a transaction, the callback is called immediately.
In a transaction, multiple callbacks may be registered and will be called once the transaction commits, in the order in which they were registered. If the transaction fails, the callbacks will not be called.
If the callback raises an exception, it bubbles up normally. This means:
- If the callback is called immediately, any exception it raises will bubble up immediately.
- If the call is postponed until
commit, remaining callbacks will be skipped and the exception will
bubble up through the
transaction()
call. However, the transaction is already committed at that point.
clear_cache
clear_cache()
Clears the in-memory cache.
NOTE: This does not affect memcache.
default_cache_policy
@staticmethod
default_cache_policy( key )
Default cache policy.
This defers to _use_cache
on the Model
class.
Args | |
---|---|
key
|
Key instance. |
Returns | |
---|---|
A bool or None .
|
default_datastore_policy
@staticmethod
default_datastore_policy( key )
Default Datastore policy.
This defers to _use_datastore
on the Model
class.
Args | |
---|---|
key
|
Key instance. |
Returns | |
---|---|
A bool or None .
|
default_memcache_policy
@staticmethod
default_memcache_policy( key )
Default Memcache policy.
This defers to _use_memcache
on the Model
class.
Args | |
---|---|
key
|
Key instance. |
Returns | |
---|---|
A bool or None .
|
default_memcache_timeout_policy
@staticmethod
default_memcache_timeout_policy( key )
Default Memcache timeout policy.
This defers to _memcache_timeout
on the Model
class.
Args | |
---|---|
key
|
Key instance. |
Returns | |
---|---|
Memcache timeout to use (integer), or None .
|
delete
delete(
key, **ctx_options
)
flush
flush()
get
get(
key, **ctx_options
)
Returns a Model
instance given the entity key.
It will use the context cache if the cache policy for the given key is enabled.
Args | |
---|---|
key
|
Key instance. |
**ctx_options
|
Context options. |
Returns | |
---|---|
A Model instance if the key exists in the datastore; None otherwise.
|
get_cache_policy
get_cache_policy()
Return the current context cache policy function.
Returns | |
---|---|
A function that accepts a Key instance as argument and returns
a bool indicating if it should be cached. May be None .
|
get_datastore_policy
get_datastore_policy()
Return the current context datastore policy function.
Returns | |
---|---|
A function that accepts a Key instance as argument and returns
a bool indicating if it should use the datastore. May be None .
|
get_indexes
get_indexes(
**ctx_options
)
get_memcache_policy
get_memcache_policy()
Return the current memcache policy function.
Returns | |
---|---|
A function that accepts a Key instance as argument and returns
a bool indicating if it should be cached. May be None .
|
get_memcache_timeout_policy
get_memcache_timeout_policy()
Return the current policy function for memcache timeout (expiration).
in_transaction
in_transaction()
Return whether a transaction is currently active.
iter_query
iter_query(
query, callback=None, pass_batch_into_callback=None, options=None
)
map_query
map_query(
query,
callback,
pass_batch_into_callback=None,
options=None,
merge_future=None
)
memcache_add
memcache_add(
key, value, time=0, namespace=None, deadline=None
)
memcache_cas
memcache_cas(
key, value, time=0, namespace=None, deadline=None
)
memcache_decr
memcache_decr(
key, delta=1, initial_value=None, namespace=None, deadline=None
)
memcache_delete
memcache_delete(
key, seconds=0, namespace=None, deadline=None
)
memcache_get
memcache_get(
key, for_cas=False, namespace=None, use_cache=False, deadline=None
)
An auto-batching wrapper for memcache.get()
or .get_multi()
.
Args | |
---|---|
key
|
Key to set. This must be a string; no prefix is applied. |
for_cas
|
If True , request and store CAS ids on the Context.
|
namespace
|
Optional namespace. |
deadline
|
Optional deadline for the RPC. |
Returns | |
---|---|
A Future (!) whose return value is the value retrieved from
memcache, or None .
|
memcache_gets
memcache_gets(
key, namespace=None, use_cache=False, deadline=None
)
memcache_incr
memcache_incr(
key, delta=1, initial_value=None, namespace=None, deadline=None
)
memcache_replace
memcache_replace(
key, value, time=0, namespace=None, deadline=None
)
memcache_set
memcache_set(
key, value, time=0, namespace=None, use_cache=False, deadline=None
)
put
put(
entity, **ctx_options
)
set_cache_policy
set_cache_policy(
func
)
Set the context cache policy function.
Args | |
---|---|
func
|
A function that accepts a Key instance as argument and returns
a bool indicating if it should be cached. May be None .
|
set_datastore_policy
set_datastore_policy(
func
)
Set the context datastore policy function.
Args | |
---|---|
func
|
A function that accepts a Key instance as argument and returns
a bool indicating if it should use the datastore. May be None .
|
set_memcache_policy
set_memcache_policy(
func
)
Set the memcache policy function.
Args | |
---|---|
func
|
A function that accepts a Key instance as argument and returns a bool indicating if it should be cached. May be None. |
set_memcache_timeout_policy
set_memcache_timeout_policy(
func
)
Set the policy function for memcache timeout (expiration).
If the function returns 0
, it implies the default timeout.
Args | |
---|---|
func
|
A function that accepts a key instance as argument and returns
an integer indicating the desired memcache timeout. May be None .
|
transaction
transaction(
callback, **ctx_options
)
urlfetch
urlfetch(
url,
payload=None,
method='GET',
headers={},
allow_truncated=False,
follow_redirects=True,
validate_certificate=None,
deadline=None,
callback=None
)