Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ehcache缓存在目录/tmp被系统清理导致异常 #2693

Closed
weibin992 opened this issue Sep 1, 2022 · 1 comment
Closed

ehcache缓存在目录/tmp被系统清理导致异常 #2693

weibin992 opened this issue Sep 1, 2022 · 1 comment
Assignees
Labels
bug Something isn't working development completed Development completed, waiting for release pending verification This problem needs to be confirmed

Comments

@weibin992
Copy link

触发场景描述

  1. 读取Excel大文件使用了ehcache缓存,默认缓存文件存放于/tmp目录下,此目录会被系统定时清理不活跃文件
  2. com.alibaba.excel.cache.Ehcache 此类的CacheManager为静态变量,在类初始化时缓存路径被固定为/tmp下的某个目录
  3. 当我上传一次,之后隔了十几天再次上传大文件,此时缓存根目录已被系统清理,无法创建缓存文件导致异常

触发Bug的代码

EasyExcel.read(stream, listener).sheet(sheetIndex).doRead();

提示的异常

Caused by: org.ehcache.CachePersistenceException: Unable to create or reuse directory: /tmp/e1d50dbf-0368-40f4-a1da-43acb9b18a9b/excache/409492a2-54a9-48e4-bbb5-02e27b297968/file
        at org.ehcache.impl.persistence.FileUtils.create(FileUtils.java:98)
        at org.ehcache.impl.persistence.DefaultLocalPersistenceService.createSafeSpace(DefaultLocalPersistenceService.java:166)
        at org.ehcache.impl.persistence.DefaultDiskResourceService.createSpace(DefaultDiskResourceService.java:150)
        at org.ehcache.impl.persistence.DefaultDiskResourceService.getPersistenceSpaceIdentifier(DefaultDiskResourceService.java:109)
        at org.ehcache.core.EhcacheManager.getStore(EhcacheManager.java:439)
        ... 61 common frames omitted

临时解决方案

  1. 修改java.io.tmpdir为其他目录
  2. 通过反射取得类初始化时的缓存根目录,每次调用前检测目录是否存在,不存在则创建
@zhuangjiaju
Copy link
Collaborator

已经在最新版本修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working development completed Development completed, waiting for release pending verification This problem needs to be confirmed
Projects
None yet
Development

No branches or pull requests

3 participants