1 package com.sun.syndication.fetcher.impl; 2 3 import java.util.Collections; 4 import java.util.LinkedHashMap; 5 import java.util.Map; 6 7 /*** 8 * <p>An implementation of the {@link com.sun.syndication.fetcher.impl.FeedFetcherCache} interface.</p> 9 * 10 * <p>Unlike the HashMapFeedInfoCache this implementation will not grow unbound</p> 11 * 12 * @author Javier Kohen 13 * @author Nick Lothian 14 * 15 */ 16 public class LinkedHashMapFeedInfoCache extends HashMapFeedInfoCache { 17 private final class CacheImpl extends LinkedHashMap { 18 private static final long serialVersionUID = -6977191330127794920L; 19 20 public CacheImpl() { 21 super(16, 0.75F, true); 22 } 23 24 protected boolean removeEldestEntry(Map.Entry eldest) { 25 return size() > getMaxEntries(); 26 } 27 } 28 29 private static final int DEFAULT_MAX_ENTRIES = 20; 30 31 private static final long serialVersionUID = 1694228973357997417L; 32 33 private int maxEntries = DEFAULT_MAX_ENTRIES; 34 35 private final static LinkedHashMapFeedInfoCache _instance = new LinkedHashMapFeedInfoCache(); 36 37 38 /*** 39 * Get the global instance of the cache 40 * @return an implementation of FeedFetcherCache 41 */ 42 public static final FeedFetcherCache getInstance() { 43 return _instance; 44 } 45 46 /*** 47 * <p>Constructor for HashMapFeedInfoCache</p> 48 * 49 * <p>Only use this if you want multiple instances of the cache. 50 * Usually {@link #getInstance()} is more appropriate.</p> 51 * 52 * @see #getInstance() 53 */ 54 public LinkedHashMapFeedInfoCache() { 55 super(); 56 } 57 58 protected Map createInfoCache() { 59 return Collections.synchronizedMap(new CacheImpl()); 60 } 61 62 public synchronized final int getMaxEntries() { 63 return maxEntries; 64 } 65 66 public synchronized final void setMaxEntries(int maxEntries) { 67 this.maxEntries = maxEntries; 68 } 69 70 }