0

I have a question about how .get(key) works.

If i use an complex object as a key, i figured out that the equals function is not called. But which reference the framework used to identify the key objects.

I need to know which one is faster? String or Object as key?

SancezZ
  • 43
  • 4

1 Answers1

0

This is the get function, getCacheControl() is returning a IMemoryCache<K, V> implementation.

https://github.com/apache/commons-jcs/blob/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/CacheAccess.java

@Override
    public V get( K name )
    {
        ICacheElement<K, V> element = this.getCacheControl().get( name );

        return ( element != null ) ? element.getVal() : null;
    } 

AbstractMemoryCache implementing IMemoryCache and using a Map,
https://github.com/apache/commons-jcs/blob/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java

/** Map where items are stored by key.  This is created by the concrete child class. */
    public Map<K, MemoryElementDescriptor<K, V>> 

So we can assume similar semantics. Composite objects should not make any difference, maybe you forgot to override hashCode. Map first uses it to find the bucket, later uses equals.