Cache Persistence Manager Factory
This tutorial will guide you through setting up an embedded Onyx In-Memory Database, configuring the connection using the Cache Persistence Manager Factory, and performing basic operations.
Note: Cloud vs. Open Source Implementation
This guide focuses on the Onyx Open Source Database. In contrast, the Onyx Cloud Database offers managed services where persistence managers are encapsulated, eliminating the need for manual configuration. For more details on the cloud implementation, refer to our comprehensiveUser Guide for Onyx Cloud Database.
The cloud database provides additional features such as enhanced security, scalability, and automated backups.
Download Example Code on GitHub
Why Use Cache Persistence Manager Factory?
The Cache Persistence Manager Factory is used to configure your In-Memory Database with the Onyx Cache. The cache compresses and indexes your data, allowing you to store and access entities efficiently using off-heap resources, while benefiting from all Onyx Database ORM features.
Note: It is recommended to create a global singleton instance of the factory, rather than constructing a new manager every time it's needed.
Example: Using CachePersistenceManagerFactory
Below is an example of how to set up the CachePersistenceManagerFactory in both Kotlin and Java.
Add Gradle Dependency
1repositories {
2 mavenCentral()
3 maven {
4 url = uri("https://maven.pkg.github.com/OnyxDevTools/onyx-database-parent")
5 credentials {
6 username = "github_username" // Replace with your GitHub username
7 password = "github_access_token" // Replace with your GitHub access token
8 }
9 }
10}
11
12dependencies {
13 implementation("com.onyxdevtools:onyx-database:3.4.4") // Embedded Database
14 implementation("com.onyxdevtools:onyx-remote-database:3.4.4") // Remote Database Server
15 implementation("com.onyxdevtools:onyx-remote-driver:3.4.4") // Remote Database Client
16}
Create an Instance of CacheManagerFactory
1val factory = CacheManagerFactory()
2factory.initialize()
3
4val manager = factory.persistenceManager
Get the PersistenceManager from the Factory
Save, Query, Update, and Delete Entities
Close the Cache Manager Factory
1factory.close()
Troubleshooting
- OutOfMemoryException: Ensure you have enough memory in order to support the CacheManagerFactory.
Next Steps
Congratulations! You've successfully set up an embedded Onyx Cache Database. To further enhance your knowledge, proceed to the next tutorials: