Cache Queries

Ignite .NET supports a very elegant query API with support for

For SQL queries Ignite supports in-memory indexing, so all the data lookups are extremely fast. If you are caching your data in off-heap memory, then query indexes will be cached in off-heap memory as well.

Main Abstractions

ICache has several query methods all of which receive some sublcass of QueryBase class and return IQueryCursor.
##QueryBase
QueryBase abstract class represents an abstract paginated query to be executed on the distributed cache. You can set the page size for the returned cursor via Query.PageSize property.

IQueryCursor

IQueryCursor represents query result set and allows for transparent page-by-page iteration. Whenever user starts iterating over the last page, it will automatically request the next page in the background. For cases when pagination is not needed, you can use IQueryCursor.GetAll() method which will fetch the whole query result and store it in a collection.

📘

Closing Cursors

Cursors will close automatically if you call method QueryCursor.GetAll(). If you are iterating over the cursor, you must Dispose() the cursor explicitly or use 'using' keyword. Using 'foreach' loop will automatically call Dispose().

Scan Queries

Scan queries allow for querying cache in distributed form based on some user defined predicate.

var cache = ignite.GetOrCreateCache<int, Person>("myCache");

// Create query and get a cursor.
var cursor = cache.Query(new ScanQuery<int, Person>(new QueryFilter()));

// Iterate over results. Using 'foreach' loop will close the cursor automatically.
foreach (var cacheEntry in cursor)
    Console.WriteLine(cacheEntry.Value);

SQL Queries

Ignite SQL queries are covered in a separate section SQL Queries.

Text Queries

Ignite also supports text-based queries based on Lucene indexing.

var cache = ignite.GetOrCreateCache<int, Person>("myCache");

// Query for all people with "Master Degree" in their resumes.
var cursor = cache.Query(new TextQuery("Person", "Master Degree"));

// Iterate over results. Using 'foreach' loop will close the cursor automatically.
foreach (var cacheEntry in cursor)
    Console.WriteLine(cacheEntry.Value);