Feature

Caching

At A Glance

Backendless Caching API provides a way to temporarily store data on our server in a highly efficient, in-memory cache. Cache storage accepts key-value pairs, where the key is a string and the value can be a primitive or a complex data structure (arrays, complex types, maps/dictionaries, etc). Caching works cross-platform – Backendless automatically adapts your data between different client types. For example, an Android client can put an instance of a Person-type Java object into cache, and an iOS (or any other) client will retrieve that object as an instance of its native class.

Caching

Caching API

Our Universal Caching API is available in all Backendless SDKs (Android/Java, iOS, JS, .NET and REST). The API provides the functionality to place any kind of data into a server-side cache, retrieve it from the cache, and check if data is available in the cache. For example:

// PUT DATA INTO CACHE
var countries = [ 'Afghanistan', 'Albania', 'Algeria', '...' ];
var key = 'countriesList';

// PUT INTO CACHE
await Backendless.Cache.put( key, countries, timeToLive );

// GET FROM CACHE
var valueFromCache = await Backendless.Cache.get( key );

.NET
JAVA
KOTLIN
OBJECTIVE-C
SWIFT
JS
FLUTTER
REST
Backendless.InitApp( YOUR-APP-ID, YOUR-DOTNET-API-KEY );

 

// PUT DATA INTO CACHE
var countries = new [] { “Afghanistan”, “Albania”, “Algeria”, “…” };
await Backendless.Cache.PutAsync( “countriesList”, countries );

 

// EXTEND TIME IN CACHE
await Backendless.Cache.ExpireInAsync( “countriesList”, 7200 );

 

// GET VALUE FROM CACHE
var valueFromCache = await Backendless.Cache.GetAsync( “countriesList” );

Backendless.initApp(context, YOUR_APP_ID, YOUR_API_KEY);

 

// PUT DATA INTO CACHE
List countries = Arrays.asList( “Afghanistan”, “Albania”, “Algeria”, “…” );
Backendless.Cache.put( “countriesList”, countries );

 

// EXTEND TIME IN CACHE
Backendless.Cache.expireIn( “countriesList”, 7200 );

 

// GET VALUE FROM CACHE
List valueFromCache = Backendless.Cache.get( “countriesList”, List.class );

Backendless.initApp(context, YOUR_APP_ID, YOUR_API_KEY)

 

// PUT DATA INTO CACHE
val countries = listOf(“Afghanistan”, “Albania”, “Algeria”, “…”)
Backendless.Cache.put(“countriesList”, countries)

 

// EXTEND TIME IN CACHE
Backendless.Cache.expireIn(“countriesList”, 7200)

 

// GET VALUE FROM CACHE
val valueFromCache = Backendless.Cache.get(“countriesList”, List::class.java)

[Backendless.shared initAppWithApplicationId:YOUR_APP_ID apiKey:YOUR_IOS_API_KEY];

 

// ***********************************************************************
// PUT DATA INTO CACHE
// ***********************************************************************

 

NSArray *countries = @[@”Afghanistan”, @”Albania”, @”Algeria”, @”…”];
[Backendless.shared.cache putWithKey:@”countriesList” object:countries responseHandler:^{
// success
} errorHandler:^(Fault *fault) {
// failure
}];

 

// ***********************************************************************
// EXTEND TIME IN CACHE
// ***********************************************************************

 

[Backendless.shared.cache expireInKey:@”countriesList” seconds:7200 responseHandler:^{
// success
} errorHandler:^(Fault *fault) {
// failure
}];

 

// ***********************************************************************
// GET VALUE FROM CACHE
// ***********************************************************************

 

[Backendless.shared.cache getWithKey:@”countriesList” responseHandler:^(id result) {
// success
} errorHandler:^(Fault *fault) {
// failure
}];

Backendless.shared.initApp(applicationId: YOUR_APP_ID, apiKey: YOUR_IOS_API_KEY)
        
// ***********************************************************************
// PUT DATA INTO CACHE
// ***********************************************************************
        
let countries = ["Afghanistan", "Albania", "Algeria", "..."]
Backendless.shared.cache.put(key: "countriesList", object: countries, responseHandler: {
    // success
}, errorHandler: { fault in
    // failure
})
        
// ***********************************************************************
// EXTEND TIME IN CACHE
// ***********************************************************************
        
Backendless.shared.cache.expireIn(key: "countriesList", seconds: 7200, responseHandler: {
    // success
}, errorHandler: { fault in
    // failure
})
        
// ***********************************************************************
// GET VALUE FROM CACHE
// ***********************************************************************
        
Backendless.shared.cache.get(key: "countriesList", responseHandler: { result in
    // success
}, errorHandler: { fault in
    // failure
 })

Backendless.initApp( YOUR-APP-ID, YOUR-JS-API-KEY );

// PUT DATA INTO CACHE
var countries = [ 'Afghanistan', 'Albania', 'Algeria', '...' ];
var key = 'countriesList';

var timeToLive = 3600; // default value is 7200 seconds

Backendless.Cache.put( key, countries, timeToLive )
 .then( function( result ) {
 })
 .catch( function( error ) {
 });

// EXTEND TIME IN CACHE
Backendless.Cache.expireIn( key, 7200 )
 .then( function( result ) {
 })
 .catch( function( error ) {
 });

// GET VALUE FROM CACHE
Backendless.Cache.get( 'countriesList' )
 .then( function( valueFromCache ) {
 })
 .catch( function( error ) {
 });

Backendless.initApp(YOUR_APP_ID, YOUR_ANDROID_API_KEY, YOUR_IOS_API_KEY);

// PUT DATA INTO CACHE
List countries = ["Afghanistan", "Albania", "Algeria", "..."];
await Backendless.Cache.put("countriesList", countries);

// EXTEND TIME IN CACHE
await Backendless.Cache.expireIn("countriesList", 7200);

// GET VALUE FROM CACHE
dynamic valueFromCache = await Backendless.Cache.get("countriesList",);

// INCREMENT COUNTER BY 1
curl ‘https://api.backendless.com///counters/ordersReceived/increment/get’ -X PUT

// INCREMENT COUNTER BY 5
curl ‘https://api.backendless.com///counters/ordersReceived/incrementby/get?value=5’ -X PUT

// GET COUNTER VALUE
curl ‘https://api.backendless.com///counters/ordersReceived’

// RESET COUNTER
curl ‘https://api.backendless.com///counters/ordersReceived/reset’ -X PUT

Graphical Cache Management

Backendless Console displays a complete listing of everything stored in your cache. You can create new cache entries, and modify or delete existing ones.

Cross-Platform Cached Data

Backendless Cache automatically transforms cached data between different environments. For example, suppose an Android version of your app places a Java array into cache and the iOS version retrieves the data. Backendless Cache ensures that the array is converted into an Objective-C or Swift collection. As a result, you do not need to write any additional code to transform the data. The same is true for all data types.