缓存测试

注入cache:

package gov.mof.fasp2.mu.xz.test;


import com.longtu.framework.cache.service.ICacheService;
import com.longtu.framework.cache.service.ICacheInit;
import com.longtu.framework.util.StringUtil;

public class InjectCache implements ICacheInit {
    private ICacheService myCache;

    public ICacheService getMyCache() {
        return myCache;
    }

    public void setMyCache(ICacheService myCache) {
        this.myCache = myCache;
    }

    @Override
    public void initCache(ICacheService cacheService) {
        for (int i = 0; i < 10; i++) {
            String str = "longtu";
            str = (str + i).toString();
            myCache.put(str, StringUtil.getCRCString(str));
        }
    }

}

配置xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cache="http://www.springframework.org/schema/fasp2/cache"
    xmlns:distributed="http://www.springframework.org/schema/fasp2/distributed"
    xmlns:communication="http://www.springframework.org/schema/fasp2/communication"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/fasp2/distributed
        http://www.springframework.org/schema/fasp2/distributed/distributed.xsd
        http://www.springframework.org/schema/fasp2/cache
        http://www.springframework.org/schema/fasp2/cache/cache.xsd
        http://www.springframework.org/schema/fasp2/communication
        http://www.springframework.org/schema/fasp2/communication/communication.xsd
        ">
    <cache:domain id="cache" initbeanid="xzFirstCache"></cache:domain>
    <bean id="xzFirstCache" class="gov.mof.fasp2.mu.xz.test.InjectCache">
        <property name="myCache">
            <ref bean="cache"></ref>
        </property>
    </bean>
</beans>

jsp测试界面:

<%@page import="com.longtu.framework.cache.service.CacheManager"%>
<%@page import="com.longtu.framework.cache.service.ICacheService"%>
<%@page import="com.longtu.framework.util.ServiceFactory"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <h1>缓存测试</h1>
    <%    ICacheService cache=(ICacheService)ServiceFactory.getBean("cache");
        String cachename=cache.getCacheName();
        Set keys=cache.getKeys();
        Iterator i= keys.iterator();
        while(i.hasNext()){
            String key=(String)i.next();
            String value=(String)cache.get(key);
        
    %>
    <%=key %>---------<%=value %>
    <br>
    <%} %>
    <%=cachename %>
</body>
</html>

结果:

缓存测试_第1张图片

总算是不报错了,菜狗要感谢上帝。。

 

你可能感兴趣的:(缓存测试)