How do I divide Dao and Dao-Cache into different modules? I want to improve performance for api. I design cache in dao layer. I use caffine cache. Basic code is:
CacheConfig.java
@Configuration
public class CacheConfig {

    @Autowired
    private AppDao appDao;

    @Bean(value = &quot;appCache&quot;)
    public LoadingCache&lt;String, App&gt; appCache() {
        return Caffeine.newBuilder()
                .maximumSize(1000)
                .refreshAfterWrite(5, TimeUnit.MINUTES)
                .build(key -&gt; appDao.getByKeyFromDB(key));
    }
}


AppDao.java
@Repository
public class AppDao {

    @Autowired
    @Qualifier(value = &quot;appCache&quot;)
    private LoadingCache&lt;String, App&gt; appCache;

    @Autowired
    private AppMapper appMapper;

    // service call getByAppKey
    public App getByKey(String appKey) {
        App app = appCache.get(appKey);
        return app;
    }

    // appCache load data by getByKey
    public App getByKeyFromDB(String appKey) {
        LambdaQueryWrapper&lt;App&gt; queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(App::getAppKey, appKey);
        return appMapper.selectOne(queryWrapper);
    }
}

I maybe divide getByKey and getByKeyFromDB to two file, but I have no idea.
How do I divide getByKey and getByKeyFromDB to different modules?
Well if you want to distinct classes, you should create two classes:
class CahedDao {
  AppCache cache;
  getByKey(String)
} 

class DbDao {
  getByKeyFromDb(String)
}

Notes:
A. Codereview is to review working code, if you want to solve a problem you should better ask on stackexchange.
B. There are some issues in your code. Thanks to the DI and (bad) field injection you did not got them.