Directs the predictive cache to preload a related collection for a Set along with other elements of the Set.
A Set containing the same elements as s. The resulting Set will include a hint that instructs the predictive cache framework to retrieve the related set property from the DataDomain whenever the resulting Set is enumerated.
The method directs the predictive cache to preload a related set property for s along with other elements of it. Specifying complex expressions for set precache or precaching nested sets are currently not supported.
Calling the PrecacheSet method does not access the database immediately. However, Genome executes a separate query for each precached collection directly before s is executed.
The retrieved collections are stored in the Context cache. Precached collections of items in s 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.
Cached sets can be invalidated manually by calling the QueryCacheManager.Invalidate method.
Cached sets are not consistent with changes. Modifying a persistent object in a way that affects the items in the cached set will not be reflected in the cached set content, unless the set is invalidated in the cache. Currently, the PrecacheSet method cannot be used with indexed collections.
To use a set property for predictive caching, the member should provide a specific set that describes the relation between the persistent instances represented by the collection. This relation is automatically provided for the most common collection structures or can be specified manually using <Relation> element . Automatic relation analysis supports set properties mapped with <Oql> element . The following list contains a few examples of set structures that can be analysed automatically.
| OQL Query | Generated Relation |
|---|---|
| extentof(B)[b: b.A == this] | [new object[] { A, this }]extentof(B) |
| extentof(B)[b: b.A == this && b.Value < 5] | [new object[] { A, this }]extentof(B)[b: b.Value < 5] |
| extentof(B)[b: b.A == this].Order([Text descending]) | [new object[] { A, this }]extentof(B).Order([Text descending]) |
| [B]extentof(AB)[ab: ab.A == this] | [new object[] { A, B }]extentof(AB) |
| [B]extentof(AB)[ab: ab.A == this].Order([B.Text descending]) | [new object[] { A, B }]extentof(AB).Order([B.Text descending]) |
| [B]extentof(AB)[B.Value < 5][ab: ab.A == this] | [new object[] { A, B }]extentof(AB)[B.Value < 5] |
| Exception Type | Condition |
|---|---|
| PredictiveCachingException | The related set property does not support set precaching. |
using(Context.Push(LocalContext.Create()))
{
Cages cages = dataDomain.Extent(typeof(Cage))["Size > 2"];
cages = PredictiveCacheManager.PrecacheSet(cages, "Inhabitants");
foreach (Cage cage in cages)
{
Console.WriteLine("Cage: {0}", cage);
foreach (Animal a in cage.Inhabitants)
{
Console.WriteLine(" {0}", a);
}
}
}
Namespace: TechTalk.Genome
Assembly: TechTalk.Genome (in TechTalk.Genome.dll)
Version: 4.2.4.4
Editions: Professional, Evaluation
PredictiveCacheManager Class | TechTalk.Genome Namespace | <Relation> Element