package cn.superdesk.uniorder.config.mybatis;


import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.Method;
import java.util.Arrays;

@Slf4j
@Configuration
public class MybatisCacheConfig {

	/**
	 * 最好是返回一个的
	 *
	 * @return
	 */
	@Bean("findByXXKeyGenerator")
	public KeyGenerator keyGenerator() {
		return new KeyGenerator() {
			@Override
			public Object generate(Object o, Method method, Object... objects) {


				log.info("缓存 MybatisCacheConfig->keyGenerator(alias:findByXXKeyGenerator) key {}", method.getName() + "[" + Arrays.asList(objects).toString() + "]");

				return method.getName() + "[" + Arrays.asList(objects).toString() + "]";
			}
		};
	}
}
