1. 程式人生 > >Java後臺框架篇--Spring之快取

Java後臺框架篇--Spring之快取

複製程式碼
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(); } }
複製程式碼