Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在EhCache-java中从持久存储中获取数据_Java_Android_Caching_Ehcache - Fatal编程技术网

如何在EhCache-java中从持久存储中获取数据

如何在EhCache-java中从持久存储中获取数据,java,android,caching,ehcache,Java,Android,Caching,Ehcache,我使用了Ehcache的persistent存储来缓存和存储数据。 这是我得到的代码: import org.ehcache.PersistentCacheManager; import org.ehcache.config.units.EntryUnit; import org.ehcache.config.units.MemoryUnit; import java.io.IOException; import static org.ehcache.config.builders.Cach

我使用了
Ehcache
persistent
存储来缓存和存储数据。
这是我得到的代码:

import org.ehcache.PersistentCacheManager;
import org.ehcache.config.units.EntryUnit;
import org.ehcache.config.units.MemoryUnit;

import java.io.IOException;

import static org.ehcache.config.builders.CacheConfigurationBuilder.newCacheConfigurationBuilder;
import static org.ehcache.config.builders.CacheManagerBuilder.newCacheManagerBuilder;
import static org.ehcache.config.builders.CacheManagerBuilder.persistence;
import static org.ehcache.config.builders.ResourcePoolsBuilder.newResourcePoolsBuilder;

public class home {
    public static void main(String[] args) throws IOException {
        //  Creating Persistent Cache
        PersistentCacheManager persistentCacheManager =
                newCacheManagerBuilder()
                        .with(persistence("/tmp/tempProjectCache"))
                        .withCache("test-cache",
                                newCacheConfigurationBuilder(
                                        String.class, String.class,
                                        newResourcePoolsBuilder()
                                                .heap(1, EntryUnit.ENTRIES)
                                                .offheap(1, MemoryUnit.MB)
                                                .disk(2, MemoryUnit.MB, true)
                                )
                        ).build(true);

        org.ehcache.Cache persistantCacheStorage = persistentCacheManager.getCache("test-cache", String.class, String.class);
        persistantCacheStorage.put("name1","prince");
        persistantCacheStorage.put("name2","steven");
        System.out.println(persistantCacheStorage.get("name1"));
    }

}
输出
获取:

prince
效果很好。数据进入了磁盘。 下一次,我从源代码中删除了这一行

persistantCacheStorage.put("name1","prince");
从代码中选择并运行代码
现在,
输出

null 
由于它是
持久的
存储,因此数据已经存储在磁盘上。为什么它不能从磁盘获取已经存储的数据。 我不知道我做错了什么。如果是用文件重新创建文件夹,那么如何避免这种情况并利用
EHCache
中的旧缓存数据我是
java
的新手。帮我解决一些问题