Using the Cache Sub-Producer

CodeFluent Entities provides an integrated cache system for the Business Object Model (BOM) layer.  The Object Model Cache (OMC) is not enabled by default. To add the cache feature to your BOM you need to first add a Cache sub producer.

The Cache Sub-Producer

The Cache Sub-Producer

If you set the “Is Default Enable” attribute to “True” the cache feature will be enabled for all the entities in your model. You can also decide to enable or not the cache feature by entity or by method.
Enable Cache on an Entity

Enable Cache on an Entity

As you can see in the image above, you can independently specify whether you want to enable the cache feature for Collections or not by changing the value of the “Is Collection Enabled” attribute.
If you enable the cache feature, when calling a “LoadXXX” method (ex. Load, LoadById…) on your entity will make that a cache verification is performed before trying to load the data from the data source (SQL server for example).
If you want to bypass the cache you can call the “NoCacheLoadXXX” method (ex. NoCacheLoad, NoCacheLoadById…). When saving or deleting an instance of an entity, the cache is cleared (for that entity) and you can clear manually the cache calling the “CacheClear” method on an entity (public static method).
You may considerate some points when using a Cache system:

  • Complexity will be added to your application.
  • Unexpected behaviors may appear if not using it correctly.
  • The Object Model Cache provided by default is an in-memory cache, so it cannot be shared between servers.
  • It is not interesting to use a Cache system if the cached data changes too often. It’s best to cache immutable or almost immutable data.

An example scenario when the Object Model Cache feature could be useful may be when storing “referential” data on a data base or data that does not change too often.
CodeFluent entities provides three types of Cache implementations:

  • Simple Cache Manager, based on the ASP .NET cache (that can be used outside of ASP.NET)  (CodeFluent.Runtime.Caching.SimpleCacheManager, CodeFluent.Runtime).
  • Simple Localized Cache Manager, a sub-class of the Simple Cache Manager that can manage localized keys (CodeFluent.Runtime.Caching.LocaleCacheManager, CodeFluent.Runtime)
  • Enterprise Library Cache Management, you must install the Enterprise Library in order to use it (CodeFluent.Runtime.Caching.EnterpriseLibraryCacheManager, CodeFluent.Runtime).

You can specify the type of cache you want to use on the “Runtime Cache Type Name” attribute (the full type name). You can use a different cache systems by scope (entity, method).

Runtime Cache Type Name

Runtime Cache Type Name


You can use a different or custom type of cache not provided by CodeFluent Entities, you only need to implement the CodeFluent.Runtime.Caching.ICacheManager interface.


Finally, you can disable the cache feature by configuration (only for the Simple Cache Manager and the Simple Localized Cache Manager), for a testing or development environment for example. You only need to add the following code to your app.config or web.config file:

   <add key="CodeFluent.Runtime.Caching.SimpleCacheManager.Enabled" value="false"/>


Pablo Fernandez Duran

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s