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.

Backendless.Cache.expireIn( key, seconds )
 .then( function( result ) {
 })
 .catch( function( error ) {
 });

Backendless.Cache.expireAt( key, timestamp )
 .then( function( result ) {
 })
 .catch( function( error ) {
 });

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).
timestamp a timestamp in milliseconds when the object should expire and removed from cache. The difference between timestamp and the current time must be equal or less than 7200000 milliseconds (2 hours).

Example

var successCallback = function( response ) {
  console.log( "[ASYNC] object's life has been extended/set" );
};

var failureCallback = function( fault ) {
  console.log( "error - " + fault.message );
};

Backendless.Cache.expireIn( "firstorder", 1200 )
 .then( successCallback )
 .catch( failureCallback );

Backendless.Cache.expireAt( "firstorder", new Date( new Date().getTime() + 1200 ) )
 .then( successCallback )
 .catch( failureCallback );