1414
1515"""Context for currently running tasks and transactions."""
1616
17+ from google .cloud .ndb import exceptions
18+
1719
1820__all__ = ["AutoBatcher" , "Context" , "ContextOptions" , "TransactionOptions" ]
1921
@@ -22,13 +24,237 @@ class AutoBatcher:
2224 __slots__ = ()
2325
2426 def __init__ (self , * args , ** kwargs ):
25- raise NotImplementedError
27+ raise exceptions . NoLongerImplementedError ()
2628
2729
2830class Context :
29- __slots__ = ()
31+ def clear_cache (self ):
32+ """Clears the in-memory cache.
3033
31- def __init__ (self , * args , ** kwargs ):
34+ This does not affect memcache.
35+ """
36+ raise NotImplementedError
37+
38+ def flush (self ):
39+ """Force any pending batch operations to go ahead and run."""
40+ raise NotImplementedError
41+
42+ def get_cache_policy (self ):
43+ """Return the current context cache policy function.
44+
45+ Returns:
46+ Callable: A function that accepts a
47+ :class:`~google.cloud.ndb.key.Key` instance as a single
48+ positional argument and returns a ``bool`` indicating if it
49+ should be cached. May be :data:`None`.
50+ """
51+ raise NotImplementedError
52+
53+ def get_datastore_policy (self ):
54+ """Return the current context datastore policy function.
55+
56+ Returns:
57+ Callable: A function that accepts a
58+ :class:`~google.cloud.ndb.key.Key` instance as a single
59+ positional argument and returns a ``bool`` indicating if it
60+ should use the datastore. May be :data:`None`.
61+ """
62+ raise NotImplementedError
63+
64+ def get_memcache_policy (self ):
65+ """Return the current memcache policy function.
66+
67+ Returns:
68+ Callable: A function that accepts a
69+ :class:`~google.cloud.ndb.key.Key` instance as a single
70+ positional argument and returns a ``bool`` indicating if it
71+ should be cached. May be :data:`None`.
72+ """
73+ raise NotImplementedError
74+
75+ def get_memcache_timeout_policy (self ):
76+ """Return the current policy function memcache timeout (expiration).
77+
78+ Returns:
79+ Callable: A function that accepts a
80+ :class:`~google.cloud.ndb.key.Key` instance as a single
81+ positional argument and returns an ``int`` indicating the
82+ timeout, in seconds, for the key. :data:`0` implies the default
83+ timeout. May be :data:`None`.
84+ """
85+ raise NotImplementedError
86+
87+ def set_cache_policy (self , policy ):
88+ """Set the context cache policy function.
89+
90+ Args:
91+ policy (Callable): A function that accepts a
92+ :class:`~google.cloud.ndb.key.Key` instance as a single
93+ positional argument and returns a ``bool`` indicating if it
94+ should be cached. May be :data:`None`.
95+ """
96+ raise NotImplementedError
97+
98+ def set_datastore_policy (self , policy ):
99+ """Set the context datastore policy function.
100+
101+ Args:
102+ policy (Callable): A function that accepts a
103+ :class:`~google.cloud.ndb.key.Key` instance as a single
104+ positional argument and returns a ``bool`` indicating if it
105+ should use the datastore. May be :data:`None`.
106+ """
107+ raise NotImplementedError
108+
109+ def set_memcache_policy (self , policy ):
110+ """Set the memcache policy function.
111+
112+ Args:
113+ policy (Callable): A function that accepts a
114+ :class:`~google.cloud.ndb.key.Key` instance as a single
115+ positional argument and returns a ``bool`` indicating if it
116+ should be cached. May be :data:`None`.
117+ """
118+ raise NotImplementedError
119+
120+ def set_memcache_timeout_policy (self , policy ):
121+ """Set the policy function for memcache timeout (expiration).
122+
123+ Args:
124+ policy (Callable): A function that accepts a
125+ :class:`~google.cloud.ndb.key.Key` instance as a single
126+ positional argument and returns an ``int`` indicating the
127+ timeout, in seconds, for the key. :data:`0` implies the default
128+ timout. May be :data:`None`.
129+ """
130+ raise NotImplementedError
131+
132+ def call_on_commit (self , callback ):
133+ """Call a callback upon successful commit of a transaction.
134+
135+ If not in a transaction, the callback is called immediately.
136+
137+ In a transaction, multiple callbacks may be registered and will be
138+ called once the transaction commits, in the order in which they
139+ were registered. If the transaction fails, the callbacks will not
140+ be called.
141+
142+ If the callback raises an exception, it bubbles up normally. This
143+ means: If the callback is called immediately, any exception it
144+ raises will bubble up immediately. If the call is postponed until
145+ commit, remaining callbacks will be skipped and the exception will
146+ bubble up through the transaction() call. (However, the
147+ transaction is already committed at that point.)
148+
149+ Args:
150+ callback (Callable): The callback function.
151+ """
152+ raise NotImplementedError
153+
154+ def in_transaction (self ):
155+ """Get whether a transaction is currently active.
156+
157+ Returns:
158+ bool: :data:`True` if currently in a transaction, otherwise
159+ :data:`False`.
160+ """
161+ raise NotImplementedError
162+
163+ @staticmethod
164+ def default_cache_policy (key ):
165+ """Default cache policy.
166+
167+ This defers to :meth:`~google.cloud.ndb.model.Model._use_cache`.
168+
169+ Args:
170+ key (google.cloud.ndb.model.key.Key): The key.
171+
172+ Returns:
173+ Union[bool, NoneType]: Whether to cache the key.
174+ """
175+ raise NotImplementedError
176+
177+ @staticmethod
178+ def default_datastore_policy (key ):
179+ """Default cache policy.
180+
181+ This defers to :meth:`~google.cloud.ndb.model.Model._use_datastore`.
182+
183+ Args:
184+ key (google.cloud.ndb.model.key.Key): The key.
185+
186+ Returns:
187+ Union[bool, NoneType]: Whether to use datastore.
188+ """
189+ raise NotImplementedError
190+
191+ @staticmethod
192+ def default_memcache_policy (key ):
193+ """Default memcache policy.
194+
195+ This defers to :meth:`~google.cloud.ndb.model.Model._use_memcache`.
196+
197+ Args:
198+ key (google.cloud.ndb.model.key.Key): The key.
199+
200+ Returns:
201+ Union[bool, NoneType]: Whether to cache the key.
202+ """
203+ raise NotImplementedError
204+
205+ @staticmethod
206+ def default_memcache_timeout_policy (key ):
207+ """Default memcache timeout policy.
208+
209+ This defers to :meth:`~google.cloud.ndb.model.Model._memcache_timeout`.
210+
211+ Args:
212+ key (google.cloud.ndb.model.key.Key): The key.
213+
214+ Returns:
215+ Union[int, NoneType]: Memcache timeout to use.
216+ """
217+ raise NotImplementedError
218+
219+ def memcache_add (self , * args , ** kwargs ):
220+ """Direct pass-through to memcache client."""
221+ raise NotImplementedError
222+
223+ def memcache_cas (self , * args , ** kwargs ):
224+ """Direct pass-through to memcache client."""
225+
226+ raise NotImplementedError
227+
228+ def memcache_decr (self , * args , ** kwargs ):
229+ """Direct pass-through to memcache client."""
230+ raise NotImplementedError
231+
232+ def memcache_delete (self , * args , ** kwargs ):
233+ """Direct pass-through to memcache client."""
234+ raise NotImplementedError
235+
236+ def memcache_get (self , * args , ** kwargs ):
237+ """Direct pass-through to memcache client."""
238+ raise NotImplementedError
239+
240+ def memcache_gets (self , * args , ** kwargs ):
241+ """Direct pass-through to memcache client."""
242+ raise NotImplementedError
243+
244+ def memcache_incr (self , * args , ** kwargs ):
245+ """Direct pass-through to memcache client."""
246+ raise NotImplementedError
247+
248+ def memcache_replace (self , * args , ** kwargs ):
249+ """Direct pass-through to memcache client."""
250+ raise NotImplementedError
251+
252+ def memcache_set (self , * args , ** kwargs ):
253+ """Direct pass-through to memcache client."""
254+ raise NotImplementedError
255+
256+ def urlfetch (self , * args , ** kwargs ):
257+ """Fetch a resource using HTTP."""
32258 raise NotImplementedError
33259
34260
0 commit comments