Getting started with examples

  1. Download the project
  2. Install Sharedcache.com distributed caching system (provided in the contribs directory). If sharedcache.com server is located on a different machine, you must edit the "Examples\AOPCaching.Example\App.config" file and set the IP address of the sharedcache.com server.
  3. Build caching componets using the provided NANT script. Project sources are located in the "Src" directory (go in the Src directory, and launch "Build AOP Caching Components Debug.bat"). Build files are located in the "Build\AOP Caching Components" Directory
  4. Build the example using the provided NANT script. Example sources are located in the "Examples" directory (launch "Build AOP Caching DEMO.bat").
  5. Use MBUnit to run unit tests. Tests success should confirm that install is OK.
  6. Have a look at the example program (open AOPCaching.Example.sln in Visual Studio), and look at the DTO class (MerchantProductsDTO), at the business class (MerchantProducts) and at the Main method: very easy of use.

Cacheable attribute

Apply this attribute to the methods you want to be cached. Methods you want to cache should respect the following points:
  • Have a return value
  • Have zero to many parameters
  • Parameters should be simple types only (can be complex types, but return value in cache will not vary according to these parameters)
  • Parameters shouldn't be out parameters

Cache component will build, for each call to the method, a unique identifier based on:
  • Return type
  • Method name
  • Parameters names and values

If this key already exist in cache, then the corresponding value gets returned. Otherwise, method is executed, and on method success, the return value is cached.

Cache singletons

As a same domain object may be returned by differents methods, we implemented the cache singleton concept. Example: your e-commerce website sells shoes. A same unique shoes model may be displayed on different pages, and selected according to many differents parameters. A couple of different methods may probably be used.

Remark: it is useless to have multiple instances of the domain object that correspond to these shoes in your caching system:
  • Higher memory consumption
  • Same work done multiple time (i.e. loading the object from the repository)
  • Harder to implement cache invalidation, as you have to identify and destoy many instances in cache to be sure that displayed info is up to date

To solve this problem, use the following attributes:
  • CacheSingleton
  • CacheSingletonIdentifier

The first is defined on domain classes (i.e. see MerchantProductDTO class), to tell the system that objects of this type should not be instanciated/stored many times in cache.

CacheSingleton

See MerchantProductDTO for further info on how to implement this attribute. The CacheSingletonIdentifier should be defined at least once in a class where CacheSingleton attribute is set.

CacheSingletonIdentifier

CacheSingletonIdentifier has two different usages. It can be applied:
  • To domain objects, on all properties that make it unique (i.e. identifier/key properties)
  • On method that defines the Cacheable Attribute, in order to match method parameters and domain object key(s)/identifier(s)

See MerchantProductDTO domain class and MerchantProducts Business class for further info on how to implement this attribute.

JITL (Just In Time Loading)

What is JITL? JITL is the idea of loading resources, only when you really need to. Example (from the program.cs file):

//Need to load some domain object using a business method.
//JITL Aspects actually interrupt the call to the GetDto method (but you don't see it)
MerchantProductDTO dto = MerchantProducts.GetDto(50);

//Need to access a domain object property
//MerchantProducts.GetDto(50) is actually called NOW
//Object is then tagged as "loaded", further access to the object won't  trigger a call to the MerchantProducts.GetDto(50) method
String Model = dto.MerchantProductModel;


When is it useful?
  • When you work on large lists of domain objects. You might retrieve/load many objects from the repository, BUT only use a couple.

Last edited Aug 27, 2010 at 9:13 AM by pierrus, version 15

Comments

No comments yet.