Skip to content

Commit 60066eb

Browse files
committed
Fixed removed files and master-main
1 parent b686d2f commit 60066eb

File tree

6 files changed

+123
-314
lines changed

6 files changed

+123
-314
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## App Engine Datastore NDB Cache Samples
2+
3+
[![Open in Cloud Shell][shell_img]][shell_link]
4+
5+
[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png
6+
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=appengine/standard/ndb/cache/README.md
7+
8+
This contains snippets used in the NDB cache documentation, demonstrating
9+
various operations on ndb caches.
10+
11+
<!-- auto-doc-link -->
12+
These samples are used on the following documentation page:
13+
14+
> https://cloud.google.com/appengine/docs/python/ndb/cache
15+
16+
<!-- end-auto-doc-link -->
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.appengine.ext import ndb
16+
17+
18+
def set_in_process_cache_policy(func):
19+
context = ndb.get_context()
20+
context.set_cache_policy(func)
21+
22+
23+
def set_memcache_policy(func):
24+
context = ndb.get_context()
25+
context.set_memcache_policy(func)
26+
27+
28+
def bypass_in_process_cache_for_account_entities():
29+
context = ndb.get_context()
30+
context.set_cache_policy(lambda key: key.kind() != 'Account')
31+
32+
33+
def set_datastore_policy(func):
34+
context = ndb.get_context()
35+
context.set_datastore_policy(func)
36+
37+
38+
def set_memcache_timeout_policy(func):
39+
context = ndb.get_context()
40+
context.set_memcache_timeout_policy(func)
41+
42+
43+
def clear_cache():
44+
context = ndb.get_context()
45+
context.clear_cache()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.appengine.ext import ndb
16+
17+
import snippets
18+
19+
20+
def test_set_in_process_cache_policy(testbed):
21+
def policy(key):
22+
return 1 == 1
23+
24+
snippets.set_in_process_cache_policy(policy)
25+
assert policy == ndb.get_context().get_cache_policy()
26+
27+
28+
def test_set_memcache_policy(testbed):
29+
def policy(key):
30+
return 1 == 2
31+
32+
snippets.set_memcache_policy(policy)
33+
assert policy == ndb.get_context().get_memcache_policy()
34+
35+
36+
def test_bypass_in_process_cache_for_account_entities(testbed):
37+
context = ndb.get_context()
38+
assert context.get_cache_policy() == context.default_cache_policy
39+
snippets.bypass_in_process_cache_for_account_entities()
40+
assert context.get_cache_policy() != context.default_cache_policy
41+
42+
43+
def test_set_datastore_policy(testbed):
44+
def policy(key):
45+
return key is None
46+
47+
snippets.set_datastore_policy(policy)
48+
assert ndb.get_context().get_datastore_policy() == policy
49+
50+
51+
def test_set_memcache_timeout_policy(testbed):
52+
def policy(key):
53+
return 1
54+
55+
snippets.set_memcache_timeout_policy(policy)
56+
assert ndb.get_context().get_memcache_timeout_policy() == policy
57+
58+
59+
def test_clear_cache(testbed):
60+
snippets.clear_cache()

datalabeling/AUTHORING_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md
1+
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md

datalabeling/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md
1+
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/CONTRIBUTING.md

0 commit comments

Comments
 (0)