I am using JCache for caching web responses. The cache key includes following fields:
- controller: String
- action: String
- parameters: Array
I created ResponseKey class and use it as a cache key type:
public class ResponseKey implements Serializable {
private String controller;
private String action;
private Object[] parameters;
@Override
public int hashCode() { // IMPL }
@Override
public boolean equals(Object obj) { // IMPL }
}
Sample codes (works fine):
JCache<ResponseKey, byte[]> cache = ...
ResponseKey key = new ResponseKey("category", "list", new Object[] { 1 });
cache.put(key, bytesContent);
Another approach is using String as a cache key type:
JCache<String, byte[]> cache = ...
String key = "/category/list/1";
cache.put(key, bytesContent);
Since String type is lighter than ResponseKey type for serialization/deserialization.
My question is: Should I use String key instead of ResponseKey key?