Retrieves values from the set and stores them in the context cache.
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.
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.
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);
}
}
Namespace: TechTalk.Genome
Assembly: TechTalk.Genome (in TechTalk.Genome.dll)
Version: 4.2.4.4
Editions: Professional, Evaluation, Express
QueryCacheManager Class | TechTalk.Genome Namespace | QueryCacheManager.CacheSet<T> Overload List | CacheSet<S> | PredictiveCacheManager.Precache<S>