Local Cache
At this point you should already know how to create, edit, list and delete data from Etebase. However, as you may have noticed, in order to edit Etebase collections and items, you need to have them objects themselves to work with. Something you don't always have.
For example, to edit a collection's content you will call setContent
on an existing collection object.
This is fine if you already have the collection object, but what if you just started the app and don't have a collection object already?
You could just fetch the object each time before changing it, though it's both inefficient and in many cases incorrect.
The correct solution to this problem is to be able to save the objects to a local cache and load them afterwards, which is what this section is about.
Cache objects are encrypted
Cache objects are encrypted so you can store them locally without worrying.
Storing and loading from cache is quite easy and is almost exactly the same for collections and items. The cache objects are just binary blobs, though if you require them to be valid strings you can convert them using the Base64 utilitis as shown below.
Saving and loading collections
- JavaScript
- Python
- Java
- Kotlin
- C/C++
- Rust
// Create a collection
const collection = await collectionManager.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
const cacheBlob = collectionManager.cacheSave(collection);
// Later on we can load the object back
const collection = collectionManager.cacheLoad(cacheBlob);
// And use it like any other object:
await collection.setContent("New content");
# Create a collection
collection = col_mgr.create(...)
# The cache blob is just a bytes object that can be saved for later use
cache_blob = col_mgr.cache_save(collection)
# Later on we can load the object back
collection = col_mgr.cache_load(cache_blob)
# And use it like any other object:
collection.content = b"New content"
// Create a collection
Collection collection = colMgr.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
byte[] cacheBlob = colMgr.cacheSave(collection);
// Later on we can load the object back
Collection collection = colMgr.cacheLoad(cacheBlob);
// And use it like any other object:
collection.setContent("New content");
// Create a collection
val collection = colMgr.create(...)
// The cache blob is just a Uint8Array that can be saved for later use
val cacheBlob = colMgr.cacheSave(collection)
// Later on we can load the object back
val collection = colMgr.cacheLoad(cacheBlob)
// And use it like any other object:
collection.content = "New content"
// Create a collection
EtebaseCollection *col = etebase_collection_manager_create(...);
// The cache blob is just a Uint8Array that can be saved for later use
uintptr_t cache_size;
void *cache_blob = etebase_collection_manager_cache_save(col_mgr, col, &cache_size);
// Later on we can load the object back
EtebaseCollection *col = etebase_collection_manager_cache_load(col_mgr, cache_blob, cache_size)
// And use it like any other object:
etebase_collection_get_uid(col);
free(cache_blob);
// Create a collection
let collection = collection_manager.create(...)?;
// The cache blob is just a Uint8Array that can be saved for later use
let cache_blob = collection_manager.cache_save(&collection)?;
// Later on we can load the object back
let mut collection = collection_manager.cache_load(&cache_blob)?;
// And use it like any other object:
collection.set_content(b"New content")?;
As Base64 encoded string
- JavaScript
- Python
- Java
- Kotlin
- C/C++
- Rust
// Create a collection
const collection = await collectionManager.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
const cacheB64 = Etebase.toBase64(collectionManager.cacheSave(collection));
// Later on we can load the object back
const collection = collectionManager.cacheLoad(Etebase.fromBase64(cacheB64));
// And use it like any other object:
await collection.setContent("New content");
from etebase import Base64Url
# Create a collection
collection = col_mgr.create(...)
# The cache blob is just a bytes object that can be saved for later use
cache_b64 = Base64Url.to_base64(col_mgr.cache_save(collection))
# Later on we can load the object back
collection = col_mgr.cache_load(Base64Url.from_base64(cache_blob))
# And use it like any other object:
collection.content = b"New content"
// Create a collection
Collection collection = colMgr.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
String cacheB64 = Utils.toBase64(colMgr.cacheSave(collection));
// Later on we can load the object back
Collection collection = colMgr.cacheLoad(Utils.fromBase64(cacheB64));
// And use it like any other object:
collection.setContent("New content");
// Create a collection
val collection = colMgr.create(...)
// The cache blob is just a Uint8Array that can be saved for later use
val cacheB64 = Utils.toBase64(colMgr.cacheSave(collection))
// Later on we can load the object back
val collection = colMgr.cacheLoad(Utils.fromBase64(cacheB64))
// And use it like any other object:
collection.content = "New content"
// Create a collection
EtebaseCollection *col = etebase_collection_manager_create(...);
// The cache blob is just a Uint8Array that can be saved for later use
uintptr_t cache_size;
void *cache_blob = etebase_collection_manager_cache_save(col_mgr, col, &cache_size);
char cache_b64[ETEBASE_UTILS_TO_BASE64_MAX_LEN(cache_size)];
etebase_utils_to_base64(cache_blob, cache_size, cache_b64, sizeof(cache_b64));
// Later on we can load the object back
char decoded[ETEBASE_UTILS_FROM_BASE64_MAX_LEN(strlen(cache_b64))];
uintptr_t decoded_len = 0;
etebase_utils_from_base64(cache_b64, decoded, sizeof(decoded), &decoded_len);
EtebaseCollection *col = etebase_collection_manager_cache_load(col_mgr, decoded, decoded_len)
// And use it like any other object:
etebase_collection_get_uid(col);
free(cache_blob);
// Create a collection
let collection = collection_manager.create(...)?;
// The cache blob is just a Uint8Array that can be saved for later use
let cache_b64 = utils::to_base64(&collection_manager.cache_save(&collection)?)?;
// Later on we can load the object back
let mut collection = collection_manager.cache_load(&utils::from_base64(&cache_b64)?)?;
// And use it like any other object:
collection.set_content(b"New content")?;
Saving and loading items
- JavaScript
- Python
- Java
- Kotlin
- C/C++
- Rust
// Create an item
const item = await itemManager.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
const cacheBlob = itemManager.cacheSave(item);
// Later on we can load the object back
const item = itemManager.cacheLoad(cacheBlob);
// And use it like any other object:
await item.setContent("New content");
# Create an item
item = item_mgr.create(...)
# The cache blob is just a bytes object that can be saved for later use
cache_blob = item_mgr.cache_save(item)
# Later on we can load the object back
item = item_mgr.cache_load(cache_blob)
# And use it like any other object:
item.content = b"New content"
// Create an item
Item item = itemManager.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
byte[] cacheBlob = itemManager.cacheSave(item);
// Later on we can load the object back
Item item = itemManager.cacheLoad(cacheBlob);
// And use it like any other object:
item.setContent("New content");
// Create an item
val item = itemManager.create(...)
// The cache blob is just a Uint8Array that can be saved for later use
val cacheBlob = itemManager.cacheSave(item)
// Later on we can load the object back
val item = itemManager.cacheLoad(cacheBlob)
// And use it like any other object:
item.content = "New content"
// Create a item
EtebaseItem *item = etebase_item_manager_create(...);
// The cache blob is just a Uint8Array that can be saved for later use
uintptr_t cache_size;
void *cache_blob = etebase_item_manager_cache_save(item_mgr, item, &cache_size);
// Later on we can load the object back
EtebaseItem *item = etebase_item_manager_cache_load(item_mgr, cache_blob, cache_size)
// And use it like any other object:
etebase_item_get_uid(item);
free(cache_blob);
// Create an item
let item = item_manager.create(...)?;
// The cache blob is just a Uint8Array that can be saved for later use
let cache_blob = item_manager.cache_save(&item)?;
// Later on we can load the object back
let mut item = item_manager.cache_load(&cache_blob)?;
// And use it like any other object:
item.set_content(b"New content")?;
As Base64 encoded string
- JavaScript
- Python
- Java
- Kotlin
- C/C++
- Rust
// Create an item
const item = await itemManager.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
const cacheB64 = Etebase.toBase64(itemManager.cacheSave(item));
// Later on we can load the object back
const item = itemManager.cacheLoad(Etebase.fromBase64(cacheB64));
// And use it like any other object:
await item.setContent("New content");
from etebase import Base64Url
# Create an item
item = item_mgr.create(...)
# The cache blob is just a bytes object that can be saved for later use
cache_b64 = Base64Url.to_base64(item_mgr.cache_save(item))
# Later on we can load the object back
item = item_mgr.cache_load(Base64Url.from_base64(cache_blob))
# And use it like any other object:
item.content = b"New content"
// Create an item
Item item = itemManager.create(...);
// The cache blob is just a Uint8Array that can be saved for later use
String cacheB64 = Utils.toBase64(itemManager.cacheSave(item));
// Later on we can load the object back
Item item = itemManager.cacheLoad(Utils.fromBase64(cacheB64));
// And use it like any other object:
item.setContent("New content");
// Create an item
val item = itemManager.create(...)
// The cache blob is just a Uint8Array that can be saved for later use
val cacheB64 = Utils.toBase64(itemManager.cacheSave(item))
// Later on we can load the object back
val item = itemManager.cacheLoad(Utils.fromBase64(cacheB64))
// And use it like any other object:
item.content = "New content"
// Create a item
EtebaseItem *item = etebase_item_manager_create(...);
// The cache blob is just a Uint8Array that can be saved for later use
uintptr_t cache_size;
void *cache_blob = etebase_item_manager_cache_save(item_mgr, item, &cache_size);
char cache_b64[ETEBASE_UTILS_TO_BASE64_MAX_LEN(cache_size)];
etebase_utils_to_base64(cache_blob, cache_size, cache_b64, sizeof(cache_b64));
// Later on we can load the object back
char decoded[ETEBASE_UTILS_FROM_BASE64_MAX_LEN(strlen(cache_b64))];
uintptr_t decoded_len = 0;
etebase_utils_from_base64(cache_b64, decoded, sizeof(decoded), &decoded_len);
EtebaseItem *item = etebase_item_manager_cache_load(item_mgr, decoded, decoded_len)
// And use it like any other object:
etebase_item_get_uid(item);
free(cache_blob);
// Create an item
let item = item_manager.create(...)?;
// The cache blob is just a Uint8Array that can be saved for later use
let cache_b64 = utils::to_base64(&item_manager.cache_save(&item)?)?;
// Later on we can load the object back
let mut item = item_manager.cache_load(&utils::from_base64(&cache_b64)?)?;
// And use it like any other object:
item.set_content(b"New content")?;