-
Notifications
You must be signed in to change notification settings - Fork 0
Object Model Cache Producer
The Object Model Cache producer adds caching capabilities to the Business Object Model (BOM). The Object Model Cache producer is in fact a sub-producer of the Business Object Model producer.
To add a sub-producer, you can use the “Add New SubProducer” context menu of the producer node in the Producers folder node:
Once the sub-producer has been added, you must enable it globally or per entity, as demonstrated here, in the Visual Studio property grid, “Aspects and Producers Properties” tab:
For a Customer entity, the Object Model Cache producer replaces the LoadById method by the following three methods:
-
a public LoadById method that uses the cache
-
a public NoCacheLoadById method that doesn't use the cache
-
a private CacheLoadById method that does the job.
// Public Method : LoadById with Cache use
public static Customer LoadById(int id)
{
return CacheLoadById(true, id);
}
// Public Method : LoadById without Cache use
public static Customer NoCacheLoadById(int id)
{
return CacheLoadById(false, id);
}
// Private internal Method : LoadById with or without Cache use
private static Commerce.Customer CacheLoadById(bool useCache, int id)
{
if ((id == -1))
{
return null;
}
Commerce.Customer customer = null;
string cacheKey = null;
if ((useCache == true))
{
cacheKey = CodeModeler.Runtime.Caching.SimpleCacheManager.BuildCacheKey("e1e5e8e28e7b22549de97b66274a8d5a", id);
customer = Commerce.Caching.CacheManager0.Manager.Get("Commerce.Customer", cacheKey) as Commerce.Customer;
if ((customer != null))
{
return customer;
}
}
customer = new Commerce.Customer();
CodeModeler.Runtime.CodeModelerPersistence persistence = CodeModelerContext.Get(Commerce.Constants.CommerceStoreName).Persistence;
persistence.CreateStoredProcedureCommand("Commerce", "Customer", "LoadById");
persistence.AddParameter("@Id", id, ((int)(-1)));
System.Data.IDataReader reader = null;
try
{
reader = persistence.ExecuteReader();
if ((reader.Read() == true))
{
customer.ReadRecord(reader, CodeModeler.Runtime.ReloadOptions.Default);
customer.EntityState = CodeModeler.Runtime.EntityState.Unchanged;
if ((useCache == true))
{
Commerce.Caching.CacheManager0.Manager.Add("Commerce.Customer", cacheKey, customer, null);
}
return customer;
}
}
finally
{
if ((reader != null))
{
reader.Dispose();
}
persistence.CompleteCommand();
}
return null;
}
- Introduction
- Architect Guide
- Concepts
- Using Visual Studio
- Overview
- Creating a CodeModeler Project
- Visual Environment
- Project Hierarchy
- Design Surface
- Customizing Design Surfaces
- Ribbon Bar
- Property Grid
- Member Format Expressions
- Model Grid
- Method Editor
- View Editor
- Instance Editor and Grid
- Resources Editor
- Inferred Model Viewer
- Building
- Project Physical Layout
- Source Control Support
- Generating
- Aspect Oriented Design (AOD)
- Developer Guide
- The Business Object Model (BOM)
- CodeModeler Query Language (CMQL)
- Starting Guide - Tutorial
- Upgrade From CFE