[Java programming language only]

Cache key considerations

WebSphere® eXtreme Scale uses hash maps to store data in the grid, where a Java™ object is used for the key.

Guidelines

When choosing a key, consider the following requirements:
  • Keys can never change. If a portion of the key needs to change, then the cache entry should be removed and reinserted.
  • Keys should be small. Since keys are used in every data access operation, it's a good idea to keep the key small so that it can be serialized efficiently and use less memory.
  • Implement a good hash and equals algorithm. The hashCode and equals(Object o) methods must always be overridden for each key object.
  • Cache the key's hashCode. If possible, cache the hash code in the key object instance to speed up hashCode() calculations. Since the key is immutable, the hashCode should be cacheable.
  • Avoid duplicating the key in the value. When using the ObjectMap API, it is convenient to store the key inside the value object. When this is done, the key data is duplicated in memory.