@Cacheable
我通过在具有以下声明的方法上使用注释来启用缓存:
@Cacheable(value = "myCache", key = "#t+ '_' + #key", condition = "#key != null")
public <T> T get(String t, VendorProperty<T> key, T defaultValue) {
return get(t, key).orElse(default_value);
}
但是,NotSerializableException
如果它尝试缓存的对象不是可序列化的(例如:),则会抛出此错误DateTimeFormatter
。
我想知道是否可以仅在对象可序列化时才缓存对象以避免此异常。
我正在使用库memcache
来缓存对象simple-spring-memcache
。
PS:我无法将Serializable
接口作为DateTimeFormatter
预定义的类来实现。