<!-- 系统默认缓存 :1小时 --> <defaultCache maxElementsInMemory="50000" clearOnFlush="false" eternal="false" timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" diskSpoolBufferSizeMB="1024" maxElementsOnDisk="100000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LFU" transactionalMode="off"> </defaultCache>
上面是resouce下ehcache.xml的缓存配置
config中的相关代码
me.add(new EhCachePlugin());// 缓存配置
我的出问题的Java代码
代码片段1、
try {
ImageIO.write(buffImg, "jpg", bs);
String imgsrc = "data:image/jpg;base64," + base64.encodeToString(bs.toByteArray());
UUID uuid = UUID.randomUUID();
CacheKit.put(CACHE_NAME, uuid, code);
System.out.println(uuid+"==>"+CacheKit.get(CACHE_NAME, uuid).toString());
return AjaxResult.capatchaSuccess(uuid.toString(), imgsrc);
} catch (IOException e) {
return AjaxResult.error("验证码生成错误");
}代码片段2、
public static AjaxResult verifyCaptchaCode(String uuid, String captchaCode) {
if (uuid == null || captchaCode == null) {
return AjaxResult.error("参数错鋘!");
}
String cacheCode = CacheKit.get(CACHE_NAME, uuid);
System.out.println(uuid+"==>"+cacheCode);
return (cacheCode == null || !cacheCode.toString().equalsIgnoreCase(cacheCode)) ? AjaxResult.error("验证码错误,请检查") : AjaxResult.success("验证通过!");
}控制台打印出来的信息
e3cbf7dc-7cff-41ca-9681-2b0edc3b3ed0==>FqiM e3cbf7dc-7cff-41ca-9681-2b0edc3b3ed0==>null
波总,我第一次存入的时候立马输出是可以从缓存到中取到的,但是我在代码片段2当中取不到这个缓存值,始终为null,我的uuid是唯一值,不知道问题出在哪里?
此外,不要使用 System.out.println(..) 这种方式,用单步调试才专业