Skip to content

Instantly share code, notes, and snippets.

@ldclakmal
Created June 6, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldclakmal/801a625b52b72d7ad63e058e3311feaa to your computer and use it in GitHub Desktop.
Save ldclakmal/801a625b52b72d7ad63e058e3311feaa to your computer and use it in GitHub Desktop.
Cache Usage with Error Handling
cache:Error? result = cache.put("key1", "value1");
if (result is cache:Error) {
// implement what to do, if any error happen when inserting
// item to the cache
}
any|cache:Error result = cache.get("key1");
if (result is cache:Error) {
// implement what to do, if any error happen when retrieving
// item from the cache
}
string value = <string>result;
cache:Error? result = check cache.invalidate("key1");
if (result is cache:Error) {
// implement what to do, if any error happen when discarding
// item from the cache
}
cache:Error? result = check cache.invalidateAll();
if (result is cache:Error) {
// implement what to do, if any error happen when discarding
// item from the cache
}
boolean hasKey = cache.hasKey("key1");
string[] keys = cache.keys();
int size = cache.size();
int capacity = cache.capacity();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment