Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/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
从memcached服务器检索java对象值时,memcached服务器返回空值_Java_Caching_Memcached - Fatal编程技术网

从memcached服务器检索java对象值时,memcached服务器返回空值

从memcached服务器检索java对象值时,memcached服务器返回空值,java,caching,memcached,Java,Caching,Memcached,我执行了memcached实现,并确定了移动到memcache的对象,但从memcached获取它时遇到了一些问题。因此,在我的应用程序中,(这是一个预订系统),我可以搜索并获得结果列表,但当我选择酒店、航班或活动时,它会显示memdown,memcach error。我列出了我使用的一些代码和方法,请帮助我解决这个问题。我真的非常感谢您的帮助和提前感谢 我的应用程序是基于Struts mvc的。我在操作文件和一些jsp文件中使用了以下3种方法。 我使用以下方法来缓存已识别的对象 private

我执行了memcached实现,并确定了移动到memcache的对象,但从memcached获取它时遇到了一些问题。因此,在我的应用程序中,(这是一个预订系统),我可以搜索并获得结果列表,但当我选择酒店、航班或活动时,它会显示memdown,memcach error。我列出了我使用的一些代码和方法,请帮助我解决这个问题。我真的非常感谢您的帮助和提前感谢

我的应用程序是基于Struts mvc的。我在操作文件和一些jsp文件中使用了以下3种方法。 我使用以下方法来缓存已识别的对象

private RezSession rezSession   = null;
    //Moving identified objects to memcached server
private void setToCache(String attributeName, Object value,HttpServletRequest request) throws Exception {
    rezSession = new RezSession();
    rezSession.setAttribute(attributeName, value, request);
}

private Object getFromCache(String attributeName, HttpServletRequest request)throws Exception {
    rezSession = new RezSession();
    return (Object) rezSession.getAttribute(attributeName,request);
}

private void removeFromCache(String attributeName, HttpServletRequest request) throws Exception{
    rezSession = new RezSession();
    rezSession.removeAttribute(attributeName,request);
}
以上方法重定向到下面列出的Rezsession方法。 AbstractSessionObject是一个接口,两个java类实现了它

  • CacheSessionImplementer.java
  • HttpSessionImplementer.java
  • RezSession.java方法:-

    public  void setAttribute(String key,Object value, HttpServletRequest request) throws Exception {
        HttpSession session = request.getSession();
        try {
            //AbstractSessionObject abstractSessionObject = RezSessionFactory.getInstance().getAbstractSessionObject();
            if("ResPkgSearchForm".equals(key))
                logger.debug(">>> Setting +:- "+key + " Class:"+(value==null?null:value.getClass()));
            AbstractSessionObject abstractSessionObject = RezSessionFactory.getInstance().getSessionSpacificInstance(session);
            abstractSessionObject.setAttribute(request,key,value,null);
    
        } catch (Exception e) {
            e.printStackTrace();
            logger.fatal("error from new setAttribute",e);
        }
    }
    
    public  Object getAttribute(String key, HttpServletRequest request) throws Exception {
        HttpSession session = request.getSession();
        try {   
            //AbstractSessionObject abstractSessionObject = RezSessionFactory.getInstance().getAbstractSessionObject();
            AbstractSessionObject abstractSessionObject = RezSessionFactory.getInstance().getSessionSpacificInstance(session);
            Object value = abstractSessionObject.getAttribute(request,key,null);
            if("ResPkgSearchForm".equals(key))
                logger.debug(">>> Getting +:- "+key + " Class:"+(value==null?null:value.getClass()));
            return value;
        } catch (Exception e) {
            e.printStackTrace();
            request.setAttribute("MEMDOWN", "Y");
            logger.fatal("error from new getAttribute",e);
        }
        return null;
    }
    
    public  void removeAttribute(String key, HttpServletRequest request) {
        HttpSession session = request.getSession();
        try {
    
            AbstractSessionObject abstractSessionObject = RezSessionFactory.getInstance().getSessionSpacificInstance(session);
            abstractSessionObject.removeAttribute(request,key,null);
    
        } catch (Exception e) {
            e.printStackTrace();
            logger.debug("error from new removeAttribute",e);
        }
    }
    
  • CacheSessionImplementer.java——AbstractSessionObject:的Memcache实现者:此方法用于从Memcached获取。 下面的代码“public Object getAttribute(),CacheSessionImplementer.java”是从“public Object getAttribute(),RezSesion.java”调用的

    EngineFactory正在选择应该选择哪个缓存引擎

    private Object getCachedValue(String key, String requestString)
        throws Exception, InstantiationException, IllegalAccessException,
        ClassNotFoundException {
    Object value = get(key, requestString);
    if (value != null && value instanceof String) {
        String new_mem_key = (String) value;
        // logger.debug("key ~>"+key+" --new_mem_key ~>"+new_mem_key);
        if ("MEM".equals(((String) value).split("#")[0])) {
            logger.debug("value before------------->" + value);// --getting
                                                                // values
                                                                // correctly---1
            value = factory.getCacheEngine(memCacheKey).getObject(
                    new_mem_key);// value is ok and redirect to
                                    // EngineFactory---2
            logger.debug("value After------------->" + value);// --getting
                                                                // null for
                                                                // value---3
            if (value == null) {
                logger.debug("MEMCACH-ERROR");
                throw new NullPointerException("MEMDOWN");
            }
        }
    }
    return value;
    }
    
  • 在我的例子中,当我选择酒店、航班或活动时,在getCachedValue()方法中(在一个以上)

    所以我无法从缓存中获取值。我 在我的应用程序中,从会话移动到memcached服务器很好,但是getFromCache被卡住了。所以我想找到好的解决办法。
    谢谢。

    这些类是否实现了
    java.io.Serializable
    ?您只能在MemCache中保留序列化对象,因为它将对象存储在辅助内存中。

    这些类是否实现了
    java.io.Serializable
    ?您只能在MemCache中保留序列化对象,因为它将对象存储在辅助内存中。

    感谢您的快速回复。是的,我在CacheSessionImplementer、RezSession、AbstractSessionObject和EngineFactory以及一些主要操作类中实现了java.io.Serializable。我是否需要实现所有与memcache.Hi-nazoorden相关的java类。您存储的这些类的对象是Memcached吗?还是它们不同?我可以看到这些类用于从Cache/Session检索数据。嗨,Raghavendra,我将其存储在memcached中,该过程运行良好。但当我从memcached获取数据时,我得到的是memdown错误和null值返回。我正在使用CacheSessionImplementer.java中的代码从mecache检索数据。我用代码块更新了上述问题。再次感谢您。感谢您的快速回复。是的,我在CacheSessionImplementer、RezSession、AbstractSessionObject和EngineFactory以及一些主要操作类中实现了java.io.Serializable。我是否需要实现所有与memcache.Hi-nazoorden相关的java类。您存储的这些类的对象是Memcached吗?还是它们不同?我可以看到这些类用于从Cache/Session检索数据。嗨,Raghavendra,我将其存储在memcached中,该过程运行良好。但当我从memcached获取数据时,我得到的是memdown错误和null值返回。我正在使用CacheSessionImplementer.java中的代码从mecache检索数据。我用代码块更新了上述问题。再次感谢你。
    private Object getCachedValue(String key, String requestString)
        throws Exception, InstantiationException, IllegalAccessException,
        ClassNotFoundException {
    Object value = get(key, requestString);
    if (value != null && value instanceof String) {
        String new_mem_key = (String) value;
        // logger.debug("key ~>"+key+" --new_mem_key ~>"+new_mem_key);
        if ("MEM".equals(((String) value).split("#")[0])) {
            logger.debug("value before------------->" + value);// --getting
                                                                // values
                                                                // correctly---1
            value = factory.getCacheEngine(memCacheKey).getObject(
                    new_mem_key);// value is ok and redirect to
                                    // EngineFactory---2
            logger.debug("value After------------->" + value);// --getting
                                                                // null for
                                                                // value---3
            if (value == null) {
                logger.debug("MEMCACH-ERROR");
                throw new NullPointerException("MEMDOWN");
            }
        }
    }
    return value;
    }
    
        logger.debug("value before------------->"+value);//-----------------------------getting values correctly---1
    value = factory.getCacheEngine(memCacheKey).getObject(new_mem_key);//value is ok and redirect to EngineFactory---2
    logger.debug("value After------------->"+value);//-------------------------------getting null for value---3