TechTalk Genome v4.2

QueryCacheManager.CacheSet<T> Method (IContext, Set<T>)

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

public static Set<T> CacheSet<T>(
   IContext context,
   Set<T> s
);

Parameters

context
The context to cache the values in.
s
The source Set<T>.

Return Value

A Set<T> containing the same elements as s. The resulting Set<T> 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<T> type has to be defined in the CacheConfiguration.Add method.

Example

                      
using(Context.Push(LocalContext.Create()))
{
    Set<Cage> cages = dataDomain.Extent<Cage>()["Size > 2"];
    cages = QueryCacheManager.CacheSet<Cage>(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<Cage> cages = dataDomain.Extent<Cage>()["Size > 2"];
    cages = QueryCacheManager.CacheSet(cages);

    ... //display the cached set

    if (cages.Count > 0)
    {
        // modifying a cage size
        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<T> Overload List | CacheSet<S> | PredictiveCacheManager.Precache<S>