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.

- (void)containsWithKey:(NSString * _Nonnull)key responseHandler:^(BOOL)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func contains(key: String, responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
key identifies the object to check in cache.

Example

[Backendless.shared.cache containsWithKey:@"CacheWeather" responseHandler:^(BOOL contains) {
    if (contains) {
        NSLog(@"Object exists in cache");
    }
    else {
        NSLog(@"Object doesn't exist in cache");
    }
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.cache.contains(key: "CacheWeather", responseHandler: { contains in
    if contains {
        print("Object exists in cache")
    }
    else {
        print("Object doesn't exist in cache")
    }
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})