NamedCacheQuery Method

ScaleOut Software NamedCache API
Queries the cache for objects that have matching metadata IndexValues as specified via filter.

Namespace:  Soss.Client
Assembly:  soss_namedcache (in soss_namedcache.dll) Version:

public ICollection Query(
	IFilter filter


Type: Soss.ClientIFilter
an IFilter containing query criteria. An instance of FilterCollection is suitable for this parameter.

Return Value

Type: ICollection
IEnumerable collection of matching CachedObjectId identifiers.

StateServerException Thrown if ScaleOut StateServer is unavailable or has experienced an internal error.

using System;
using System.Collections;
using Soss.Client;

class Program
    static void Main(string[] args)

    static void CacheObjectWithIndexEntry()
        string itemToCache = "This is an item that is stored in the shared cache.";
        NamedCache cache = CacheFactory.GetCache("Sample Cache");

        // Add the item to the cache. Setting the last parameter (lockAfterInsert) to true 
        // causes this instance of the NamedCache to hold a lock on the object, allowing us to immediately
        // set its index values without worrying about other clients interfering between the calls.
        cache.Insert("ObjKey", itemToCache, new CreatePolicy(), false, true);

        ObjectMetadata metadata = new ObjectMetadata();
        metadata.IndexCollection[0] = new IndexValue("Index value 0");
        metadata.IndexCollection[1] = new IndexValue("Index value 1");
        // Set the index values, releasing the lock on the object:
        cache.SetMetadata("ObjKey", metadata, true);

    static void QueryForObject()
        NamedCache cache = CacheFactory.GetCache("Sample Cache");

        // Query for the object based on one of its index values. 
        // Leaving the other items in the FilterCollection null indicates 
        // to the query that objects' metadata can contain any value in 
        // that particular index.
        FilterCollection querySpec = new FilterCollection();
        querySpec[1] = new IndexValue("Index value 1");
        ICollection result = cache.Query(querySpec);

        // The query result contains a collection of keys that can be enumerated:
        foreach (CachedObjectId key in result)

        // Check that we only got the single object back.
        System.Diagnostics.Debug.Assert(result.Count == 1);
See Also