프로그래밍/프로그래밍팁

LinkedHashMap을 이용한 간단한 Cache 만들기..

Terry Cho 2007. 7. 28. 11:48
 final static int MAX_CACHE_SIZE=20;
 static Map cache
  = new LinkedHashMap(MAX_CACHE_SIZE,0.75f,true){
     private static final long serialVersionUID = 1;
     @Override
     protected boolean removeEldestEntry (Map.Entry eldest) {
             return size() > MAX_CACHE_SIZE;
    }
   };
 private synchronized void putCache(String userId,List <ContactList> list){
  cache.put(userId, list);
 }
 private synchronized List<ContactList> getCache(String userId){
  return (List<ContactList>)cache.get(userId);
 }

생각보다 꽤나 유용하다...
그리드형

'프로그래밍 > 프로그래밍팁' 카테고리의 다른 글

JDK 1.5 부터 등장한 ThreadPool  (0) 2008.02.27
SQL Batch  (0) 2007.11.28
대용량 Record select  (0) 2007.11.28
Java Application의 Locking 처리문제  (0) 2007.08.21
업그레이드된 개발자 되기  (6) 2007.08.20