In this blog post, we will explore how to use the Roku cache efficiently using the roRegistry and roRegistrySection , with easy explanation.
Registry
roRegistry : The Registry is an area of non-volatile storage where a small number of persistent settings can be stored
Supported methods
- GetSpaceAvailable() as Integer
- GetSectionList() as Object
- Delete(section as String) as Boolean
- Flush() as Boolean
Registry Section
roRegistrySection: A Registry Section enables the organization of settings within the registry
Supported methods
Sample code:
' Create a registry
m.deviceRegistry = CreateObject("roRegistry")
print "spaceAvailable: " m.deviceRegistry.GetSpaceAvailable()
print "sectionList: " m.deviceRegistry.GetSectionList()
' Create and interact with a custom registry section ("Amit_RegistrySection")
m.section = CreateObject("roRegistrySection", "Amit_RegistrySection")
m.section.Write("name", "amit")
m.section.Write("address", "Bangalore")
print "m.section.Read(name) : " m.section.Read("name")
print "m.section.Read(address) : " m.section.Read("address")
' Check if a section with id = "UserSettings" already exists
m.UserSettingSection = CreateObject("roRegistrySection","UserSettings")
print "UserSettingSection userId: " m.UserSettingSection.Read("userId")
Step by Step Explanation of above Code Snippet
- Create a Registry
m.deviceRegistry = CreateObject("roRegistry")
print "spaceAvailable: " m.deviceRegistry.GetSpaceAvailable()
print "sectionList: " m.deviceRegistry.GetSectionList()
Here, an instance of roRegistry
is created, and information about the available space in the registry and the list of registry sections is printed. This helps in understanding the current state of the registry.
2. Create and Interact with a Custom Registry Section (“Amit_RegistrySection”)
m.section = CreateObject("roRegistrySection", "Amit_RegistrySection")
' write key-value pair
m.section.Write("name", "amit")
m.section.Write("address", "Bangalore")
' read values stored
print "m.section.Read(name) : " m.section.Read("name")
print "m.section.Read(address) : " m.section.Read("address")
This part creates a custom registry section named “Amit_RegistrySection” and writes key-value pairs (“name” and “address”) to it. It then reads and prints the values of these keys.
3. Read from Registry Section
'registrySection with "USER_SETTINGS" already exists
m.UserSettingSection = CreateObject("roRegistrySection","USER_SETTINGS")
print "UserSettingSection userId: " m.UserSettingSection.Read("userId")
This section checks if a registry section with the ID “UserSettings” already exists. If it does, it reads and prints the value associated with the “userId” key in that section.
In Rale , you can also check your Device Registry and read/delete it.
Overall, this code demonstrates the creation, interaction, and checking of values in custom registry sections on a Roku device using the roRegistry
and roRegistrySection
components.
Here’s a list of use cases where you can leverage roRegistry and roRegistrySection for caching app data:
- App Configuration
- Favorites or Bookmarks
- Recently Viewed Items
- Search History
- Notification Preferences
- Progress and Resume Points
- User Authentication Tokens
- User Preferences for Recommendations
- In-App Purchases and Subscriptions
- Dynamic Content Feeds
- User Feedback and Ratings
- Tutorial Progress