Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Features of using redis cache in MC2.

MC2 works with 2 types of redis distributed objects: string and map collection only.

Each cache entry in MC2 bound to separate cache and key in that cache, so to get/put value to cache we should specify cache name and key.

But in Redis each object bound to name which used as a key. 

The further sections show how it works.

Map.

Redis supports plenty of objects such as  object,map,set,list or even queue. So we can use java map object as a value in Redis.

As a result MC2 cache name bound to Redis key, MC2 key bound to Map object key.

To get value from redis cache in MC2 rules we can use  GETCACHE element.

For instance to get value for key="mc2key" from cache with name "mc2cachetest" we should use the following GETCACHE element:

<GETCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2key'" RESULTVAR="outVar" />

The extracted value will be in outVar variable.

To put value to redis cache in MC2 rules we can use  PUTCACHE element.

E.g. to put value of variable inVar  to cache with name "mc2cachetest" using key="mc2key" we should use the following PUTCACHE element:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2key'" VALUEEXPR=":inVar:"/>

Also It is possible to put/get a few variables at once:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2varskey'" VARIABLESEXPR="'inVar1,inVar2,inVar3'" />

<GETCACHE CACHETYPE="'rediscache'" CACHENAME="'mc2cachetest'" KEY="'mc2varskey'" />

The variables will be created automatically during getting from cache.

String. 

For simple object like String we have no key in Redis,

So to map MC2 cache name and key into Redis key we use name and key concatenation(using colon as a separator) as a RedisKey.

For example we would like to put String value to cache with name "stringcache" using key "stringkey". it will be bound to Redis key "stringcache:stringkey".

To deal with string cache value we also can use PUTCACHE and GETCACHE elements.

E.g. for  string value described earlier the elements will be:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'stringcache'" KEY="'stringkey'" OPTIONS="'type=string'" VALUEEXPR=":inVar:"/>

<GETCACHE CACHETYPE="'rediscache'" CACHENAME="'stringcache'" KEY="'stringkey'" OPTIONS="'type=string'" RESULTVAR="outVar"/>

Moreover MC2 string object supports eviction. Redis allows to define time to live for each Redis Key. 

To define time to live we are able to use timetolive option in PUTCACHE element. The time is defined in seconds.

E.g. to define time to live in previous example to 120 second we should use the following element:

<PUTCACHE CACHETYPE="'rediscache'" CACHENAME="'stringcache'" KEY="'stringkey'" OPTIONS="'type=string,timetolive=120'" VALUEEXPR=":inVar:"/>