vendredi 29 janvier 2016

Designing a cache initializer

I need to write a caching solution for my web application.

Basically I have lists of different objects that are kept in memory using Hazelcast. Each time the application starts the objects are loaded into memory from a persistent store. From time to time, the objects are persisted again back into the store.

The application is real-time (lots of websockets receive client requests modifying the data) so I need to be able to obtain/retrieve those objects very fast based on different type of ids and/or simple search criterias.

I was thinking to have different maps where the key represents the id and the value is the the instance of the object.

For example a certain type of object I will have a number maps (or multimaps):

  1. map1: < some_internal_key, object >
  2. map2: < some_other_internal_key, object >
  3. map3: < some_other_internal_key2, object >
  4. map4: < a_search_criteria, list< objects_meeting_the_criteria > >
  5. map5: < another_search_criteria, list < objects_meeting_the_criteria > >

....

And so on.

Those objects should be synchronized across all the 10 Maps, meaning if one object is modified, those modifications should be be available into all the maps. Sometimes, because this modifications the search criterias can be affected, so some objects should be associated with other keys.

From a code perspective how would you design this mechanism ? Do you have a better idea ?

Aucun commentaire:

Enregistrer un commentaire