小编Ash*_*rki的帖子

如何为ehcache初始化对象List<>?

我需要初始化需要包含的缓存

String in key
List<Object> in value
Run Code Online (Sandbox Code Playgroud)

所以我有 CacheHelper 类,其中有

public class CacheHelper {

    private CacheManager cacheManager;

    private Cache<String,List<Person>> cacheDataList;

    private static final String CACHE_PERSON="cache_key_person";


    public CacheHelper() {


    }

    public void putInCacheFromDb(){
        System.getProperties().setProperty("java -Dnet.sf.ehcache.use.classic.lru", "true");
        cacheManager= CacheManagerBuilder
                .newCacheManagerBuilder().build();
        cacheManager.init();


        cacheDataList = cacheManager
                .createCache("cacheOfPersonList", CacheConfigurationBuilder
                        .newCacheConfigurationBuilder(
                                String.class,Person.class,
                                ResourcePoolsBuilder.heap(10)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(60,
                                TimeUnit.SECONDS))));


    }


    public void putInList(List<Person> personList){
        System.out.println("putting list in cache");
        cacheDataList.put(CACHE_PERSON,personList);
    }


}
Run Code Online (Sandbox Code Playgroud)

但是在这行代码中,我无法将对象转换为列表 String.class,Person.class,它需要是 String.class,List:

 cacheDataList = cacheManager
                    .createCache("cacheOfPersonList", CacheConfigurationBuilder
                            .newCacheConfigurationBuilder(
                                    String.class,Person.class,
                                    ResourcePoolsBuilder.heap(10)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(60,
                                    TimeUnit.SECONDS))));
Run Code Online (Sandbox Code Playgroud)

但我收到错误如下:

Incompatible types. Required Cache<String, List<Person>> but …
Run Code Online (Sandbox Code Playgroud)

java ehcache-3

6
推荐指数
1
解决办法
6461
查看次数

Get method not able to be detected by the Node.js

I am new to node and express js.Today I am learning and I have initialized node server as:

  const express = require('express')
    const bodyParser = require('body-parser')
    const cors = require('cors')

    const PORT = 3000
    const api=require('./routes/api')
    const app = express()
    app.use(bodyParser.json())
    app.use(cors())

    api.use('/api',api)

    app.get('/', function(req, res) {
        res.send('Hello from server')
    })

   app.listen(PORT, function(){
  console.log("Server running on localhost:" + PORT)
});
Run Code Online (Sandbox Code Playgroud)

I have created a folder routes inside server folder and there is api.js file which has GET method to test, …

javascript node.js express

1
推荐指数
1
解决办法
35
查看次数

标签 统计

ehcache-3 ×1

express ×1

java ×1

javascript ×1

node.js ×1