The CacheBuddy custom widget for SAP Analytics Cloud is designed to offer powerful client-side data caching by utilizing the browser’s cache memory feature. It provides a well-structured and type-safe API for storing data persistently, retrieving it efficiently, and managing a variety of data types, including numbers, strings, booleans, objects, and arrays.
One of the key features of CacheBuddy is its ability to maintain data persistence across different browser sessions and closures. Unlike session-based caching, CacheBuddy keeps cached data available until it’s explicitly deleted by the host application or the user. This lasting persistence greatly enhances application performance and responsiveness by reducing the need for repeated data retrieval from remote backend systems.
CacheBuddy makes it easy to transfer information between different stories within the SAP Analytics Cloud environment. This means that one application (like “Application A”) can store a value that another application (like “Application B”) can easily access. This design eliminates the need for extra storage services, complex data models, or complicated configurations, making data communication between various analytical applications straightforward and efficient.
Features and Advantages
Key Features:
Type-Specific Data Management: Offers dedicated methods for storing and retrieving specific data types (number, string, boolean, object, array), ensuring data integrity and simplifying development.Persistent Storage: Data is stored in localStorage, guaranteeing persistence across browser sessions, tabs, and closures until explicitly deleted by the application or user action.Cache Utility Functions: Includes methods to check for the existence of cached items, delete individual entries, or clear all CacheBuddy-managed data.Comprehensive Data Retrieval: The getAllCacheMemory() method allows for the retrieval of all cached data, with automatic type parsing for convenience.Input Validation: Incorporates basic validation for method parameters, providing console feedback for invalid inputs.Optimized Performance: Leverages browser cache memory technology to deliver fast data storage and retrieval.
Advantages:
Enhanced Application Performance: By leveraging local data storage, CacheBuddy minimizes repeated server requests, leading to faster data access and a more responsive user experience within SAP Analytics Cloud applications.Reduced Server Load: Decreased reliance on continuous backend data fetching contributes to a lower operational load on SAP Analytics Cloud servers and associated data sources.Streamlined Data Persistence: Provides an intuitive and high-level API for localStorage, simplifying the implementation of client-side data persistence compared to direct cache manipulation.Improved Data Organization: The automatic key prefixing ensures that CacheBuddy’s data is distinctly identifiable and managed within the browser’s local storage.
Video Tutorial
Cache Memory Management
This document outlines the methods available for managing cached data. These methods allow you to store, retrieve, and manipulate various data types in a temporary cache, improving application performance by reducing the need to re-fetch or re-compute data.
Storing Data in Cache
These methods are used to store different types of data in the cache, each identified by a unique ID. They all return a boolean indicating whether the operation was successful.
setNumberCacheMemory(id: string, value: number) – Stores a numerical value.setStringCacheMemory(id: string, value: string) – Stores a string value.setBooleanCacheMemory(id: string, value: boolean) – Stores a boolean value (true or false).setSelectionCacheMemory(id: string, value: Selection) – Stores a non-array JavaScript object as a JSON string.setArrayCacheMemory(id: string, value: String[]) – Stores a JavaScript array as a JSON string.
Retrieving Data from Cache
These methods are used to retrieve previously stored data from the cache using its ID.
getNumberCacheMemory(id: string) – Returns the stored number.getStringCacheMemory(id: string) – Returns the stored string.getBooleanCacheMemory(id: string) – Returns the stored boolean.getSelectionCacheMemory(id: string) – Returns the stored selection object.getArrayCacheMemory(id: string) – Retrieves and parses a stored array from the cache.
Managing Cache Entries
These methods provide functionality for checking the existence of, deleting, and retrieving all cache entries.
existCacheMemory(id: string) – Returns a boolean indicating whether a cache entry with the specified ID exists.deleteCacheMemory(id: string) – Removes the specific cache entry identified by its ID. Returns a boolean indicating success.deleteAllCacheMemory() – Deletes all entries from the cache. Returns a boolean indicating success.getAllCacheMemory() – Retrieves all items currently in the cache as a single Selection object.
Usage
To get started with CacheBuddy, simply download the CacheBuddy.json file from the link below. Then, just follow the instructions provided to install CacheBuddy in your SAP Analytics Cloud environment.
GitHub Repository: https://github.com/SAP-Custom-Widget/CacheBuddy
Direct Download: https://sap-custom-widget.rohitchouhan.com/?dl=CacheBuddy
Download the CacheBuddy.json.Go to your SAC Portal, select Stories/Analytic Application from the left sidebar, and then go to the Custom Widget tab.Click on the + icon on the right side and select the CacheBuddy.json file that you downloaded.You’re done! You can now use it in your app.
Complete Example Code:
// 1. Store a number
var isAgeStored = CacheBuddy_1.setNumberCacheMemory(“userAge”, 26);
if (isAgeStored) {
console.log([“User age stored successfully.”]);
} else {
console.log([“Failed to store user age.”]);
}
// 2. Retrieve the number
var retrievedAge = CacheBuddy_1.getNumberCacheMemory(“userAge”);
console.log([“Retrieved age: “, retrievedAge]); // Expected: 30
// 3. Store a string
var isNameStored = CacheBuddy_1.setStringCacheMemory(“userName”, “Rohit”);
console.log([“User name stored: “, isNameStored]); // Expected: true
// 4. Retrieve the string
var retrievedName = CacheBuddy_1.getStringCacheMemory(“userName”);
console.log([“Retrieved name: “, retrievedName]); // Expected: Rohit
// 5. Store a boolean
var isActiveStored = CacheBuddy_1.setBooleanCacheMemory(“userActive”, true);
console.log([“User active status stored: “, isActiveStored]); // Expected: true
// 6. Retrieve the boolean
var retrievedActive = CacheBuddy_1.getBooleanCacheMemory(“userActive”);
console.log([“Retrieved active status: “, retrievedActive]); // Expected: true
// 7. Store a selection (non-array JavaScript object)
var userSelection = {
“theme”: “dark”,
“title”: “CacheBuddy”
};
var isSelectionStored = CacheBuddy_1.setSelectionCacheMemory(“userSettings”, userSelection);
console.log([“User settings stored: “, isSelectionStored]); // Expected: true
// 8. Retrieve the selection
var retrievedSettings = CacheBuddy_1.getSelectionCacheMemory(“userSettings”);
console.log([“Retrieved settings:”, retrievedSettings]); // Expected: { theme: “dark”, notifications: true }
// 9. Store an array
var userHobbies = [“coding”,”writing”, “music”];
var isHobbiesStored = CacheBuddy_1.setArrayCacheMemory(“userHobbies”, userHobbies);
console.log([“User hobbies stored: “, isHobbiesStored]); // Expected: true
// 10. Retrieve the array
var retrievedHobbies = CacheBuddy_1.getArrayCacheMemory(“userHobbies”);
console.log([“Retrieved hobbies:”, retrievedHobbies]); // Expected: [“coding”,”writing”, “music”]
// 11. Check if an entry exists
var doesAgeExist = CacheBuddy_1.existCacheMemory(“userAge”);
console.log([“Does ‘userAge’ exist? “, doesAgeExist]); // Expected: true
var doesNonExistentExist = CacheBuddy_1.existCacheMemory(“nonExistentKey”);
console.log([“Does ‘nonExistentKey’ exist? “, doesNonExistentExist]); // Expected: false
// 12. Delete a specific cache entry
var isAgeDeleted = CacheBuddy_1.deleteCacheMemory(“userAge”);
console.log([“User age deleted: “, isAgeDeleted]); // Expected: true
var doesAgeStillExist = CacheBuddy_1.existCacheMemory(“userAge”);
console.log([“Does ‘userAge’ exist after deletion? “, doesAgeStillExist]); // Expected: false
// 13. Retrieve all cache entries (after some deletions)
var allCache = CacheBuddy_1.getAllCacheMemory();
console.log([“All current cache entries:”, allCache]);
// This will show userName, userActive, userSettings, userHobbies as objects, and userAge will be gone.
// 14. Delete all cache entries
var areAllDeleted = CacheBuddy_1.deleteAllCacheMemory();
console.log([“All cache entries deleted: “, areAllDeleted]); // Expected: true
// 15. Verify all are deleted
var finalAllCache = CacheBuddy_1.getAllCacheMemory();
console.log([“All cache entries after deleteAllCacheMemory:”, finalAllCache]); // Expected: {} or an empty Selection object
Conclusion
The CacheBuddy custom widget is a game-changer for SAP Analytics Cloud developers who want to boost application performance and ensure smooth data flow. With its solid, type-safe caching system that uses localStorage, it cuts down on backend calls and makes everything feel more responsive. Plus, its ability to transfer data directly between stories simplifies those complex analytical tasks.
The CacheBuddy custom widget for SAP Analytics Cloud is designed to offer powerful client-side data caching by utilizing the browser’s cache memory feature. It provides a well-structured and type-safe API for storing data persistently, retrieving it efficiently, and managing a variety of data types, including numbers, strings, booleans, objects, and arrays.One of the key features of CacheBuddy is its ability to maintain data persistence across different browser sessions and closures. Unlike session-based caching, CacheBuddy keeps cached data available until it’s explicitly deleted by the host application or the user. This lasting persistence greatly enhances application performance and responsiveness by reducing the need for repeated data retrieval from remote backend systems.CacheBuddy makes it easy to transfer information between different stories within the SAP Analytics Cloud environment. This means that one application (like “Application A”) can store a value that another application (like “Application B”) can easily access. This design eliminates the need for extra storage services, complex data models, or complicated configurations, making data communication between various analytical applications straightforward and efficient.Features and AdvantagesKey Features:Type-Specific Data Management: Offers dedicated methods for storing and retrieving specific data types (number, string, boolean, object, array), ensuring data integrity and simplifying development.Persistent Storage: Data is stored in localStorage, guaranteeing persistence across browser sessions, tabs, and closures until explicitly deleted by the application or user action.Cache Utility Functions: Includes methods to check for the existence of cached items, delete individual entries, or clear all CacheBuddy-managed data.Comprehensive Data Retrieval: The getAllCacheMemory() method allows for the retrieval of all cached data, with automatic type parsing for convenience.Input Validation: Incorporates basic validation for method parameters, providing console feedback for invalid inputs.Optimized Performance: Leverages browser cache memory technology to deliver fast data storage and retrieval.Advantages:Enhanced Application Performance: By leveraging local data storage, CacheBuddy minimizes repeated server requests, leading to faster data access and a more responsive user experience within SAP Analytics Cloud applications.Reduced Server Load: Decreased reliance on continuous backend data fetching contributes to a lower operational load on SAP Analytics Cloud servers and associated data sources.Streamlined Data Persistence: Provides an intuitive and high-level API for localStorage, simplifying the implementation of client-side data persistence compared to direct cache manipulation.Improved Data Organization: The automatic key prefixing ensures that CacheBuddy’s data is distinctly identifiable and managed within the browser’s local storage.Video TutorialCache Memory ManagementThis document outlines the methods available for managing cached data. These methods allow you to store, retrieve, and manipulate various data types in a temporary cache, improving application performance by reducing the need to re-fetch or re-compute data.Storing Data in CacheThese methods are used to store different types of data in the cache, each identified by a unique ID. They all return a boolean indicating whether the operation was successful.setNumberCacheMemory(id: string, value: number) – Stores a numerical value.setStringCacheMemory(id: string, value: string) – Stores a string value.setBooleanCacheMemory(id: string, value: boolean) – Stores a boolean value (true or false).setSelectionCacheMemory(id: string, value: Selection) – Stores a non-array JavaScript object as a JSON string.setArrayCacheMemory(id: string, value: String[]) – Stores a JavaScript array as a JSON string.Retrieving Data from CacheThese methods are used to retrieve previously stored data from the cache using its ID.getNumberCacheMemory(id: string) – Returns the stored number.getStringCacheMemory(id: string) – Returns the stored string.getBooleanCacheMemory(id: string) – Returns the stored boolean.getSelectionCacheMemory(id: string) – Returns the stored selection object.getArrayCacheMemory(id: string) – Retrieves and parses a stored array from the cache.Managing Cache EntriesThese methods provide functionality for checking the existence of, deleting, and retrieving all cache entries.existCacheMemory(id: string) – Returns a boolean indicating whether a cache entry with the specified ID exists.deleteCacheMemory(id: string) – Removes the specific cache entry identified by its ID. Returns a boolean indicating success.deleteAllCacheMemory() – Deletes all entries from the cache. Returns a boolean indicating success.getAllCacheMemory() – Retrieves all items currently in the cache as a single Selection object.UsageTo get started with CacheBuddy, simply download the CacheBuddy.json file from the link below. Then, just follow the instructions provided to install CacheBuddy in your SAP Analytics Cloud environment.GitHub Repository: https://github.com/SAP-Custom-Widget/CacheBuddyDirect Download: https://sap-custom-widget.rohitchouhan.com/?dl=CacheBuddy Download the CacheBuddy.json.Go to your SAC Portal, select Stories/Analytic Application from the left sidebar, and then go to the Custom Widget tab.Click on the + icon on the right side and select the CacheBuddy.json file that you downloaded.You’re done! You can now use it in your app.Complete Example Code:// 1. Store a number
var isAgeStored = CacheBuddy_1.setNumberCacheMemory(“userAge”, 26);
if (isAgeStored) {
console.log([“User age stored successfully.”]);
} else {
console.log([“Failed to store user age.”]);
}
// 2. Retrieve the number
var retrievedAge = CacheBuddy_1.getNumberCacheMemory(“userAge”);
console.log([“Retrieved age: “, retrievedAge]); // Expected: 30
// 3. Store a string
var isNameStored = CacheBuddy_1.setStringCacheMemory(“userName”, “Rohit”);
console.log([“User name stored: “, isNameStored]); // Expected: true
// 4. Retrieve the string
var retrievedName = CacheBuddy_1.getStringCacheMemory(“userName”);
console.log([“Retrieved name: “, retrievedName]); // Expected: Rohit
// 5. Store a boolean
var isActiveStored = CacheBuddy_1.setBooleanCacheMemory(“userActive”, true);
console.log([“User active status stored: “, isActiveStored]); // Expected: true
// 6. Retrieve the boolean
var retrievedActive = CacheBuddy_1.getBooleanCacheMemory(“userActive”);
console.log([“Retrieved active status: “, retrievedActive]); // Expected: true
// 7. Store a selection (non-array JavaScript object)
var userSelection = {
“theme”: “dark”,
“title”: “CacheBuddy”
};
var isSelectionStored = CacheBuddy_1.setSelectionCacheMemory(“userSettings”, userSelection);
console.log([“User settings stored: “, isSelectionStored]); // Expected: true
// 8. Retrieve the selection
var retrievedSettings = CacheBuddy_1.getSelectionCacheMemory(“userSettings”);
console.log([“Retrieved settings:”, retrievedSettings]); // Expected: { theme: “dark”, notifications: true }
// 9. Store an array
var userHobbies = [“coding”,”writing”, “music”];
var isHobbiesStored = CacheBuddy_1.setArrayCacheMemory(“userHobbies”, userHobbies);
console.log([“User hobbies stored: “, isHobbiesStored]); // Expected: true
// 10. Retrieve the array
var retrievedHobbies = CacheBuddy_1.getArrayCacheMemory(“userHobbies”);
console.log([“Retrieved hobbies:”, retrievedHobbies]); // Expected: [“coding”,”writing”, “music”]
// 11. Check if an entry exists
var doesAgeExist = CacheBuddy_1.existCacheMemory(“userAge”);
console.log([“Does ‘userAge’ exist? “, doesAgeExist]); // Expected: true
var doesNonExistentExist = CacheBuddy_1.existCacheMemory(“nonExistentKey”);
console.log([“Does ‘nonExistentKey’ exist? “, doesNonExistentExist]); // Expected: false
// 12. Delete a specific cache entry
var isAgeDeleted = CacheBuddy_1.deleteCacheMemory(“userAge”);
console.log([“User age deleted: “, isAgeDeleted]); // Expected: true
var doesAgeStillExist = CacheBuddy_1.existCacheMemory(“userAge”);
console.log([“Does ‘userAge’ exist after deletion? “, doesAgeStillExist]); // Expected: false
// 13. Retrieve all cache entries (after some deletions)
var allCache = CacheBuddy_1.getAllCacheMemory();
console.log([“All current cache entries:”, allCache]);
// This will show userName, userActive, userSettings, userHobbies as objects, and userAge will be gone.
// 14. Delete all cache entries
var areAllDeleted = CacheBuddy_1.deleteAllCacheMemory();
console.log([“All cache entries deleted: “, areAllDeleted]); // Expected: true
// 15. Verify all are deleted
var finalAllCache = CacheBuddy_1.getAllCacheMemory();
console.log([“All cache entries after deleteAllCacheMemory:”, finalAllCache]); // Expected: {} or an empty Selection objectConclusionThe CacheBuddy custom widget is a game-changer for SAP Analytics Cloud developers who want to boost application performance and ensure smooth data flow. With its solid, type-safe caching system that uses localStorage, it cuts down on backend calls and makes everything feel more responsive. Plus, its ability to transfer data directly between stories simplifies those complex analytical tasks. Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog