⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demoaction.java

📁 ehcache
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.kook.struts.action;

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.kook.struts.mode.Student;
import com.kook.struts.plugin.EhcachePlugIn;

/** 
 * MyEclipse Struts
 * Creation date: 01-09-2008
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class DemoAction extends Action {
	
	public static String EHCACHE_KEY = DemoAction.class.getName();
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		System.out.println("Entry DemoAction~~~");
		CacheManager cacheManager = EhcachePlugIn.getCacheManager();
		Cache cache = cacheManager.getCache("sampleCache");
		System.out.println("The Key In Cache?:"+cache.isKeyInCache(EHCACHE_KEY));
		System.out.println("Cache is :"+cache);
		System.out.println(EHCACHE_KEY);
		Element result = cache.get(EHCACHE_KEY);
		
		if(null==result)
		{
			System.out.println("No Data In Ehcache");
			List list = new ArrayList();
			
			for(int i=20;i<50;i++)
			{
				Student student = new Student(26,"kook"+i);
				list.add(student);
			}
			cache.put(new Element(EHCACHE_KEY,list));
			cache.flush();
			
			result = cache.get(EHCACHE_KEY);
		}

		List ehcacheList = (List)result.getValue();
		
		Iterator iter =  ehcacheList.iterator();
		
		while (iter.hasNext()) {
			Student element = (Student) iter.next();
			System.out.println("Studeng name is:"+element.getName());
		}
		cache.flush();
		
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -