Skip to main content
Version: 6.3.0

Offline Cache for storing simple data

Use when you need to save some data into local memory. This API provides you with approach similar to the HTML5's Local Storage, but implemented internally via native device API and completely device agnostic. We do not recommend using a different storage type then Offline Cache or full featured File System API that will provide you with more low-level methods.

All methods

MethodDescriptionSupported Since
loadContent()Loads content from internal storage1.0.3
saveContent()Saves content to internal storage1.0.3
listContents()List all content items saved previously to internal storage2.0.0
deleteContent()Delete content item previously saved to internal storage2.0.0
warning

Emulator has certain limitations while handling offline files. Read more here

loadContent()

Method loadContent() loads content from internal storage.

Parameters

ParamTypeRequiredDescription
uidstring
Yes
Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 and . characters

Javascript example

await sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash');

saveContent()

Method for saving content into internal storage.

Parameters

ParamTypeRequiredDescription
uidstring
Yes
Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 and . characters
contentstring
Yes
Only string variables enabled. For JSON values use JSON.Stringify()

Javascript Example

sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash')
.then(() => {
//Content was successfully saved, retrieve it.
return sos.offline.cache.loadContent('ApplicationSecret');
})
.then((content) => {
console.log('Loaded', content); // print 123SuperSecretHash
})

listContents()

List all content items saved previously to internal storage

Javascript example

await sos.offline.cache.listContents();

deleteContent()

Delete content item previously saved to internal storage.

Parameters

ParamTypeRequiredDescription
uidstring
Yes
Unique file identifier is used for later file retrieval, must contain a-z,A-Z,0-9 and . characters

Javascript example

//Store
sos.offline.cache.saveContent('ApplicationSecret', '123SuperSecretHash')
.then(() => {
//Content was successfully saved, retrieve it.
return sos.offline.cache.loadContent('ApplicationSecret');
})
.then((content) => {
console.log('Loaded', content); // print 123SuperSecretHash

// Let's delete the content now
return sos.offline.cache.deleteContent('ApplicationSecret')
})
.then(() => {
console.log("Deleted");
})
.catch((error) => { console.error(error); });

Usage with Typescript

You can also use all these methods with signageOS TypeScript.

loadContent(uid: string): Promise<string>;
saveContent(uid: string, content: string): Promise<void>;

listContents(): Promise<string[]>;
deleteContent(uid: string): Promise<void>;

Errors

Although we are doing our best, following errors may occur when working with the offline cache.

CodeTypeMessage
41001AppletNativeCacheErrorAlready saving the file with UID: uid
51001InternalNativeCacheErrorCouldn't not read the files from the offline cache.
51001InternalNativeCacheErrorCouldn't load the file from offline cache.
51001InternalNativeCacheErrorCouldn't load the file before deleting it.
51002InternalNativeCacheErrorCouldn't save the file to the offline cache.
51003InternalNativeCacheErrorFile wasn't deleted correctly.
40901AppletOfflineCacheErrorUid contains invalid characters, allowed: $$ALLOWED_CHARS$$, got $$ACTUAL_UID$$