Skip to content

Extending the life of object in cache

There are two way to extend object's life in cache - relative timeframe and fixed timeframe. With the relative timeframe a period of time is added to the timestamp of the call to determine the new expiration time. The fixed timestamp approach sets the timestamp when the object must expire from cache.

- (void)expireInKey:(NSString * _Nonnull)key seconds:(NSInteger)seconds responseHandler:^(void)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;

- (void)expireAtKey:(NSString * _Nonnull)key date:(NSDate * _Nonnull)date responseHandler:^(void)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func expireIn(key: String, seconds: Int, responseHandler: (() -> Void)!, errorHandler: ((Fault) -> Void)!)

func expireAt(key: String, date: Date, responseHandler: (() -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
key identifies the object to extend the life of in cache.
seconds number of seconds to extend the life of object in cache by. Must be a value between 1 and 7200 (2 hours).
date date when the object should expire and removed from cache. The difference between date and the current time must be equal or less than 7200000 milliseconds (2 hours).

Example

[Backendless.shared.cache expireInKey:@"CacheWeather" seconds:3600 responseHandler:^{
    NSLog(@"Object's life has been extended");
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];

//

[Backendless.shared.cache expireAtKey:@"CacheWeather" date:[NSDate dateWithTimeIntervalSinceNow:3600] responseHandler:^{
    NSLog(@"Object's life has been extended");
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.cache.expireIn(key: "CacheWeather", seconds: 3600, responseHandler: {
    print("Object's life has been extended")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})

//

Backendless.shared.cache.expireAt(key: "CacheWeather", date: Date(timeIntervalSinceNow: 3600), responseHandler: {
    print("Object's life has been extended")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})