For the complete documentation index, see llms.txt. This page is also available as Markdown.

Caches

Use GridGain 9 caches as temporary storage, create them from SQL, Java classes, or a builder, and connect a cache to an external JDBC database.

GridGain Caches are designed as temporary storage for rapid response "cache" of data that may be required for local operation.

Cache data is always stored in a special cache store. By default, the cache maintains a weak consistency with the remote storage.

Difference Between Caches and Tables

Unlike tables, in GridGain caches do not have persistence or store transaction history.

This means that caches also do not support read-only transactions and continuous queries, as those features rely on transaction history to ensure consistency.

Additionally, fields in caches cannot be nullable.

Requirements

To use caches in your project, you need to add a gridgain-jdbc-cache-store dependency:

<dependency>
    <groupId>org.gridgain</groupId>
    <artifactId>gridgain-jdbc-cache-store</artifactId>
    <version>9.1.28</version>
</dependency>

Creating a Cache

Caches are created by using the DDL CREATE CACHE command, for example:

Using SQL

You can create a cache from SQL by using the CREATE CACHE command:

You can execute this SQL from your Java application as well, for example:

From Java Class

You can use the @Cache annotation in your Java code to create caches.

You can only create caches from Key-Value POJOs.

With a Cache Builder

You can also use a builder to create a cache definition in your code instead of first creating a Java class.

When using builders, only the @Id and @Column annotations on fields are supported.

The example below creates a simple cache:

Cache-Only Transactions

Transactions cannot interact with both caches and tables at the same time. When you create a transaction, it must be specified as a cache-specific transaction by setting the cacheOnly option to true:

Caches as External Storage

Caches need to be connected to an external storage to store data permanently. When connected, you can read data directly from the external storage if required data is not available in the cache, or write data that was sent to cache into the persistent storage.

GridGain supports the JDBC cache store, which allows to connect a cache and a relational database contents.

You can use tuples or POJOs to work with the database. In the examples below we will use the following POJOs:

To connect to an external database:

  • Configure the connection to the external database:

  • Configure a cache store factory:

  • Define mapping and:

  • Create a key-value view for the table in the underlying database:

The cache is now connected to the database. Write operations to the cache will be propagated to the database, and data missing in the cache will be retrieved automatically. For example, here is how you can retrieve a key:

External Storage Write-Behind

By default, GridGain keeps the cache consistent with the connected database. You can configure your cache to copy data from clients asynchronously by setting the WRITE_MODE parameter to ASYNC.

When a cache is set to async mode, any data written to it from the client will be propagated to the database asynchronously. For example:

The cacheWriteBehindParallelOperations client configuration option defines the maximum number of parallel write behind operations for the cache (1024 by default). If the write-behind queue is full, new tasks will be performed in SYNC mode.

Only operations made from GridGain clients are propagated in asynchronous mode.

This page is: Copyright © 2026 MariaDB. All rights reserved.

spinner

Last updated

Was this helpful?