POM can store (or cache) Preactor field values in memory, therefore avoiding the need to query Preactor and therefore making your code faster.

It is important NOT to cache Preactor fields that have values that can change easily such as start and end times. (or can change out of your control, such as users changing values in the editor window.)

Here is an example of caching some properties in custom types.

Pom = new PreactorObjectModel();

// Enable Material control
Pom.EnableMaterialControl();

// Register custom types
Pom.Register<IOperation, Operation>();
Pom.Register<IResource, Resource>();

// Caching
Pom.EnablePropertyCache();

var cachedResourceProperties = TypeFilter.Properties<Resource>().IncludeAll().Names.ToList();
Pom.PropertyCacheRegister<Resource>(cachedResourceProperties);

var cachedOperationProperties = TypeFilter.Properties<Operation>()
					.Include(x => x.OrderNumber)
					.Include(x => x.OperationNumber)
					.Include(x => x.OperationName)
					.Names.ToList();

 

POM comes with a TypeFilter object which makes it easy to create a list of property names. You could just as easily write something like this:

var cachedOperationProperties = new List<string>{"OperationName", "PartNumber", "OrderNumber"};

(However we feel this is error prone and tedious.)

Some other usages of the TypeFilter are:

var properties = TypeFilter.Properties<Type>.IncludeAll().ExcludeAll<DateTime>().Names.ToString();

var properties = TypeFilter.Properties<Type>.IncludeAll().Exclude(x => x.PropertyABC).Names.ToString();

You can temporarily disable the caching:

Pom.DisablePropertyCache();

This will essentially erase the cache and call Preactor every time a value is required for a given property.

 

Last edited Aug 27, 2013 at 1:59 PM by bvsms, version 3

Comments

No comments yet.