Friday, June 25, 2010

Define Key for LogicCache

Hi, let`s speak about what key for LogicCache. Ok, not for LogicCache, for any cache.
Cache like a Map, there is key and related value. When we ask cache for a value we write the next code:
cache.get(key);
and there is a comparison like keyInsideCache.equals(key) so key`s class must override equals and hashCode.
A key may be stored to a disk store in the serialized form, so key`s class and all key`s properties`s classes must implement the java.io.Serializable interface.
Any key must contain a set of properties which influence to the result and make key unique.

In accordance to the requirements above LogicCacheKey was designed. Here is the class "diagram" :)

















LogicCacheKey contains several properties:

  • patientId - marks result for certain patient;
  • indexDate - date, LogicContext had when result was cached. We can run LogicService.eval for the past time and now. There is method updateTime which set to zero milli-/seconds, minutes, hours because of when we put "past time" we will write dd/MM/yyyy, and no HH:mm:ss.
  • dataSource - only contains canonical name of the class of the LogicDataSource implementation. We don`t need any information dataSource contains.
  • criteria - LogicCriteria which is parsed from string representation of Rule we run eval method for. I think about how to make it string which will reprpesent LogicCriteria, like dataSource.
  • parameters - some additional parameters. If this map will contain some non-serializable objects will only will not have this cache-entry stored to disk store.

Monday, June 21, 2010

Writing wrapper of caching frameworks, part2

Hi this post is about the structure of the Caching System for the Logic Module. I`ve already presented my structure, listened to question/comments and something changed it.

The main goal of this caching system is to wrap a caching framework and provide the interface for required features for us. Rest upon previous post where I made a review of simplified structure of two caching frameworks I designed a structure of the Caching System for the Logic Service.

Here is it:


















LogicCacheManager - utilitny class, provides a cache by its name, keeps Map of caches as well as a link to LogicCacheProvider.

LogicCacheProvider - class hides a control of the CacheManager of the certain caching framework. It is an abstract class. Contains a list of all created logicCaches.

LogicCache - the interface that is necessary to implement, which hides a cache of the certain caching framework, provides all the necessary methods: get, put, getSize etc. Some methods may throw IllegalOperationException, this means cachig framework behind it doesn`t support such features. Also it has getFeature method which take argument LogicCache.Feature type which is internal enumeration. Using "boolean getFeature(Feature)" we can ask our logicCache about what features are supported.

LogicCacheConfig - interface, provides access to manage some parameters of the cache at the runtime. For example: max size of the cache in the memory, default ttl for objects in cache etc. Like LogicCache it has internal enumeration LogicCacheConfig.Features and getFeature method to ask about what methods are supported.

Next post I`ll write about LogicCacheKey, serialization, how to test it.

Monday, June 14, 2010

Writing wrapper of caching frameworks, part1

My presentation was last week and I told about the design of the caching system for the logic service. As you know I`ll use a widely used caching framework which helps me to cover a bigger part of the requirements such:

  • provide an inmemory cache
  • provide a disk cache
  • expiration time for cache objects and so on.

Also one of the tasks was to design an abstraction layer for a caching framework to have opportunity to change it. We needn`t all of features of any caching framework (ehcache, jboss cache, jcs ...) and we will use only framework`s cache to get/put objects, cache manager to create caches and configuration objects to change some run time properties of the cache.

I tried to use ehcache, then I looked through the tutorial of the jboss-cache and jcs. I understood they similar in their using. All of them have configuration files to configure some central object in the meaning of the cache manager, using it we can create caches and change their configurations.

Below I provided simplified structures of ehcache and jboss-cache.

EhCache:

Using an ehcache.xml file we can create a CacheManager then we can get/create caches using the CacheManager. That`s all! we can put/get objects into/from a cache. Each cache has it`s configuration and some properties may be changed at run time.

JBoss-cache:

Using a CacheFactory and some config.xml file we can create a Cache. This cache is like a CacheManager. It has at least one ROOT node and may have a lot of them each node we can use like a cache where we can put/get objects.

There is a similar situation with jcs.

Next post I`ll write about my design to wrap caching framework.