Java後臺框架篇--Spring之快取
阿新 • • 發佈:2019-01-27
public class TestCache { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("config/spring-cache.xml"); TestCacheService testCache = (TestCacheService)context.getBean("testCache"); CacheManager cm = (CacheManager) context.getBean("cacheManager");//新增資料到快取中 testCache.get("job"); Cache uCache = cm.getCache("uCache"); //通過引數作為key,得到對應的value User u1 = (User) uCache.get("job").get(); u1.show(); //新增資料到快取中 testCache.get2(); //通過方法名作為key,得到對應value User u2 = (User) uCache.get("get2").get(); u2.show(); } }