首页 > 代码库 > Java缓存类loadingCache

Java缓存类loadingCache

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
LoadingCache<String, String> cache = CacheBuilder.newBuilder()
                    .maximumSize(1000)
                    .expireAfterAccess(3, TimeUnit.SECONDS)
                    .refreshAfterWrite(1, TimeUnit.SECONDS)
                    .build(new CacheLoader<String, String>() {
                        @Override
                        public String load(String s) throws Exception {
                            return s + "cache";
                        }
                    });
            String sss = cache.getUnchecked("sss");

 

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <encoding>UTF-8</encoding>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

 

Java缓存类loadingCache