Skip to content

Checking if key exists in cache

This API request checks if an object exists in cache. If object is present in cache, the method returns true, otherwise - false. All methods are available via Backendless.Cache.[methodname] accessor:

// synchronous method
public Boolean Contains( String key )

// asynchronous method
public void Contains( String key, AsyncCallback<Boolean> callback )

where:

Argument                Description
key identifies the object to check in cache.
callback the callback used for asynchronous calls to deliver result or fault to the calling program

Example

AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>(
result =>
{
  System.Console.WriteLine( "[ASYNC] object exists in cache - "  + result );
},
fault =>
{
  System.Console.WriteLine( "Error - " + fault );
} );

// get object from cache asynchronously
Backendless.Cache.Contains( "firstorder", callback );

// get object from cache synchronously
Boolean objectExists = Backendless.Cache.Contains( "firstorder" );
System.Console.WriteLine( "[SYNC] object exists in cache - "  + objectExists );

Codeless Reference

caching_codeless_check_if_key_exists_1

where:

Argument                Description
key name Key assigned to the object to identify it in cache. The key is used to check if the cache still contains the object.

Returns true if the key still exists in cache, otherwise returns false.

Consider the following key-value pair stored in cache:

caching_codeless_putting_data_into_cache_3

The example below checks if the key "orderName" is still stored in cache.

caching_codeless_check_if_key_exists_2

The operation returns true, indicating that the "orderName" key still exists in cache.

caching_codeless_check_if_key_exists_3