Key-Value Store
Ignite can be accessed with simple key-value APIs and, thus, act as a distributed key-value store (aka. data grid). In this scenario, you can think of Ignite as of a distributed partitioned hash map with every cluster node owning a portion of the overall data set. It's worth mentioning, that even if you see or use Ignite as a key-value store, you're not limited to the key-value operations and can always leverage from other available APIs such as SQL, collocated computations, machine learning, streaming.
Ignite key-value APIs comply with JCache (JSR 107) specification that supports the following:
- In-Memory Key Value Store
- Basic Cache Operations
- ConcurrentMap APIs
- Collocated Processing (EntryProcessor)
- Events and Metrics
- Pluggable Persistence
In addition to the standard JCache API, Ignites supports distributed ACID transactions, scan and continuous queries, collocated processing and more.
Ignite ignite = Ignition.ignite(); // Get an instance of named cache. final IgniteCache<Integer, String> cache = ignite.cache("cacheName"); // Store keys in cache. for (int i = 0; i < 10; i++) cache.put(i, Integer.toString(i)); // Retrieve values from cache. for (int i = 0; i < 10; i++) System.out.println("Got [key=" + i + ", val=" + cache.get(i) + ']'); // Remove objects from cache. for (int i = 0; i < 10; i++) cache.remove(i); // Atomic put-if-absent. cache.putIfAbsent(1, "1"); // Atomic replace. cache.replace(1, "1", "2");
Ignite ignite = Ignition.ignite(); // Clone every object we get from cache, so we can freely update it. IgniteCache<Integer, Account> cache = ignite.cache("cacheName"); try (IgniteTx tx = Ignition.ignite().transactions().txStart()) { Account acct = cache.get(acctId); assert acct != null; // Deposit $20 into account. acct.setBalance(acct.getBalance() + 20); // Store updated account in cache. cache.put(acctId, acct); tx.commit(); }
Ignite ignite = Ignition.ignite(); // Get an instance of named cache. final GridCache<String, Integer> cache = ignite.cache("cacheName"); // Lock cache key "Hello". Lock lock = cache.lock("Hello"); lock.lock(); try { cache.put("Hello", 11); cache.put("World", 22); } finally { lock.unlock(); }
More on Key-Value APIs
Feature | Description |
---|---|
Data Grid |
Ignite data grid is a |
Durable Memory |
Ignite |
JCache (JSR 107) |
Ignite is a 100% compliant implementation of JCache (JSR 107) specification. JCache provides a very simple to use, yet very powerful API for data caching: |
Memory-Centric Storage |
Apache Ignite is based on distributed memory-centric architecture that combines the performance and scale of in-memory computing together with the disk durability and strong consistency in one system: |
Collocated Processing |
Ignite allows executing any native Java, C++, and .NET/C# code directly on the server-side, close to the data, in collocated fashion: |
Client-side Near Caches |
Near cache is local client-side cache that stores the most recently and most frequently accessed data. |
ACID Transactions |
Ignite provides fully ACID compliant distributed transactions that ensure guaranteed consistency. |
Deadlock-Free Transactions |
Ignite supports deadlock-free, optimistic transactions, which do not acquire any locks, and free users from worrying about the lock order. Such transactions also provide much better performance: |
Transactional Entry Processor |
Ignite transactional entry processor allows executing collocated user logic on the server side within a transaction: |
Cross-Partition Transactions |
In Ignite, transactions can be performed on all partitions of a cache across the whole cluster: |
Locks |
Ignite allows developers to define explicit locks enforcing mutual exclusion on cached objects: |
Continuous Queries |
Continuous queries are useful for cases when you want to execute a query and then continue to get notified about the data changes that fall into your query filter: |
Write-Through |
Write-Through mode allows updating the data in the database. |
Read-Through |
Read-Through mode allows reading the data from the database. |
Write-Behind Caching |
Ignite provides an option to asynchronously perform updates to the database via Write-Behind Caching. |
Hibernate L2 Caching |
Ignite data grid can be used as |
Spring Caching |
Ignite provides Spring-annotation-based way to enable caching for Java methods so that the result of a method execution is stored in the Ignite cache. If later the same method is called with the same set of parameters, the result will be retrieved from the cache instead of actually executing the method. |
Spring Data |
Apache Ignite implements Spring Data |
OSGI Support |