class CacheKeyMethodStoreImpl implements CacheKeyMethodStore {

    @Override
    public Method getKeyMethod(final Class<?> keyClass) throws NoSuchMethodException {
        final Method storedMethod = find(keyClass);
        if (storedMethod != null) {
            return storedMethod;
        }
        Method targetMethod = getFromClass(keyClass);

        if (targetMethod == null) {
            // try to get from superclass
            Class<?> superKeyClass = keyClass.getSuperclass();
            if (superKeyClass != null) {
                targetMethod = getKeyMethod(superKeyClass);
            }

            if (targetMethod == null || DEFAULT_KEY_METHOD_NAME.equals(targetMethod.getName())) {
                targetMethod = keyClass.getMethod(DEFAULT_KEY_METHOD_NAME, (Class<?>[]) null);
            }
        }

        add(keyClass, targetMethod);

        return targetMethod;
    }

}