我可以使用ehcache搜索API搜索二级缓存吗?
如果我使用put()
方法直接用对象填充缓存,则可以使用SearchAttribute进行搜索。当我试图查询二级Hibernate缓存时,我坚持在ehcache中从一个对象的反汇编状态组装一个实体。
public class TestExtr implements AttributeExtractor {
@Override
public Object attributeFor(Element element, String arg1)
throws AttributeExtractorException {
return element.?() ; //how to cast its value to Employee?
}
}
我的实体示例
public class Employee implements Serializable {
private int id;
private String firstName;
private String lastName;
private int salary;
// getters and setters
}
二级缓存的 Element element
值为:
org.hibernate.cache.ehcache.internal.strategy.AbstractReadWriteEhcacheAccessStrategy$Item@6b8efd7c
key = test.Employee#1383
CacheEntry(test.Employee)[aaaaa,dd,77]