def sync_actions(): print("Running sync ExpiryPolicy example.") client = Client() with client.connect('127.0.0.1', 10800): print("Create cache with expiry policy.") try: ttl_cache = client.create_cache({ PROP_NAME: 'test', PROP_EXPIRY_POLICY: ExpiryPolicy(create=timedelta(seconds=1.0)) }) except NotSupportedByClusterError: print( "'ExpiryPolicy' API is not supported by cluster. Finishing...") return try: ttl_cache.put(1, 1) time.sleep(0.5) print(f"key = {1}, value = {ttl_cache.get(1)}") # key = 1, value = 1 time.sleep(1.2) print(f"key = {1}, value = {ttl_cache.get(1)}") # key = 1, value = None finally: ttl_cache.destroy() print("Create simple Cache and set TTL through `with_expire_policy`") simple_cache = client.create_cache('test') try: ttl_cache = simple_cache.with_expire_policy(access=timedelta( seconds=1.0)) ttl_cache.put(1, 1) time.sleep(0.5) print(f"key = {1}, value = {ttl_cache.get(1)}") # key = 1, value = 1 time.sleep(1.7) print(f"key = {1}, value = {ttl_cache.get(1)}") # key = 1, value = None finally: simple_cache.destroy()
student_cache = client.create_cache({ PROP_NAME: 'SQL_PUBLIC_STUDENT', PROP_SQL_SCHEMA: 'PUBLIC', PROP_QUERY_ENTITIES: [ { 'table_name': 'Student'.upper(), 'key_field_name': 'SID', 'key_type_name': 'java.lang.Integer', 'field_name_aliases': [], 'query_fields': [ { 'name': 'SID', 'type_name': 'java.lang.Integer', 'is_key_field': True, 'is_notnull_constraint_field': True, }, { 'name': 'NAME', 'type_name': 'java.lang.String', }, { 'name': 'LOGIN', 'type_name': 'java.lang.String', }, { 'name': 'AGE', 'type_name': 'java.lang.Integer', }, { 'name': 'GPA', 'type_name': 'java.math.Double', }, ], 'query_indexes': [], 'value_type_name': 'SQL_PUBLIC_STUDENT_TYPE', 'value_field_name': None, }, ], })
# # https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from pprint import pprint from pygridgain import Client client = Client() with client.connect('127.0.0.1', 10800): my_cache = client.create_cache('my cache') my_cache.put_all({'key_{}'.format(v): v for v in range(20)}) # { # 'key_0': 0, # 'key_1': 1, # 'key_2': 2, # ... 20 elements in total... # 'key_18': 18, # 'key_19': 19 # } with my_cache.scan() as cursor: for k, v in cursor: print(k, v) # 'key_17' 17 # 'key_10' 10