Onyx Database Cache Manager Factory

Cache Manager Factory
An Onyx Database tutorial on caching data
This guide walks you through how to set up Onyx Database to cache data.

You can download the code for this example here: OnyxDevTools/onyx-database-samples/cache-manager.

Why Use?

A Cache Manager Factory is used to configure your In-Memory Database. Onyx Cache compresses and indexes your data. It allows you to take advantage of accessing and storing entities using off-heap resources while also taking advantage of all the Onyx Database ORM features.
Note: It is best practice to use the factory to create a global singleton instance rather than constructing a new manager each time you use it.

Here is an example of how to use an CacheManagerFactory:

  1. Create an instance of a CacheManagerFactory.
  2. Set the database credentials.

    This step is optional. If you do not specify a username or password. The credentials will default to admin/admin.

  3. Initialize the database connection

    By initializing the cache manager factory, you will retain a lock so that it cannot be opened by another process.

  4. Get the PersistenceManager from the factory.
  5. Save stuff!

    Now that you have an instance of the PersistenceManager you can use it to save, update, query and delete entities from memory.

  6. Close the Cache Manager Factory.

    By default Onyx Database adds a JVM shutdown hook upon the termination of the process. It is always a good idea to manually call close when you are finished with the database connection in order to prevent potential data loss.

  7. Remote Persistence Manager Factory