public static void write(ServiceInfo dom, String dir) {
        
        try {
            makeSureCacheDirExists(dir);
            
            File file = new File(dir, dom.getKeyEncoded());
            createFileIfAbsent(file, false);
            
            StringBuilder keyContentBuffer = new StringBuilder();
            
            String json = dom.getJsonFromServer();
            
            if (StringUtils.isEmpty(json)) {
                json = JacksonUtils.toJson(dom);
            }
            
            keyContentBuffer.append(json);
            
            //Use the concurrent API to ensure the consistency.
            ConcurrentDiskUtil.writeFileContent(file, keyContentBuffer.toString(), Charset.defaultCharset().toString());
            
        } catch (Throwable e) {
            NAMING_LOGGER.error("[NA] failed to write cache for dom:" + dom.getName(), e);
        }
    }
@Test
    void testWriteCacheWithErrorPath() {
        File file = new File(CACHE_DIR, serviceInfo.getKeyEncoded());
        try {
            file.mkdirs();
            DiskCache.write(serviceInfo, CACHE_DIR);
            assertTrue(file.isDirectory());
        } finally {
            file.delete();
        }
    }