TechTalk Genome v4.2

QueryCacheManager.CacheSet Method (IContext, Set)

Retrieves values from the set and stores them in the context cache.

public static Set CacheSet(
   IContext context,
   Set s
);

Parameters

context
The context stores the cached values.
s
The source Set.

Return Value

A Set containing the same elements as s. The resulting Set contains a hint that instructs Genome to retrieve the items from the context cache.

Remarks

Cached sets can be accessed without executing a database query as long as the collection has not been invalidated in the cache. The caching strategy for storing precached collections can be configured in the CacheConfiguration instance specified for context creation. To specify different settings for caching collections, the Set type has to be defined in the CacheConfiguration.Add method.

Example

          
using(Context.Push(LocalContext.Create()))
{
    Set cages = dataDomain.Extent(typeof(Cage))["Size > 2"];
    cages = QueryCacheManager.CacheSet(cages);

    // these operations are served from memory
    if (cages.Count == 0)
       Console.WriteLine("No cages found.");
    else 
    {    
        foreach (Cage cage in cages)
        {
            Console.WriteLine("Cage: {0}", cage);
        }
    }
}
                

Invalidating the query cache manually

            
using(Context.Push(ShortRunningTransactionContext.Create()))
{
    Set cages = dataDomain.Extent(typeof(Cage))["Size > 2"];
    cages = QueryCacheManager.CacheSet(cages);

    ... //display the cached set

    if (cages.Count > 0)
    {
        // modifying a cage size
        Cage cage = (Cage)cages.GetItem(0);
        cage.Size = 1;
        // we need to invalidate the query cache to see the updated result
        QueryCacheManager.Invalidate(cages);
        
        Console.WriteLine("Number of cages after modification: {0}", cages.Count);
    }
}
                

Requirements

Namespace: TechTalk.Genome

Assembly: TechTalk.Genome (in TechTalk.Genome.dll)

Version: 4.2.4.4

Editions: Professional, Evaluation, Express

See Also

QueryCacheManager Class | TechTalk.Genome Namespace | QueryCacheManager.CacheSet Overload List | CacheSet