1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.fetcher.impl;
18
19 import java.io.Serializable;
20 import java.net.URL;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24
25
26 /***
27 * <p>A very simple implementation of the {@link com.sun.syndication.fetcher.impl.FeedFetcherCache} interface.</p>
28 *
29 * <p>This implementation uses a HashMap to cache retrieved feeds. This implementation is
30 * most suitible for sort term (client aggregator?) use, as the memory usage will increase
31 * over time as the number of feeds in the cache increases.</p>
32 *
33 * @author Nick Lothian
34 *
35 */
36 public class HashMapFeedInfoCache implements FeedFetcherCache, Serializable {
37 static HashMapFeedInfoCache _instance;
38
39 private Map infoCache;
40
41 /***
42 * <p>Constructor for HashMapFeedInfoCache</p>
43 *
44 * <p>Only use this if you want multiple instances of the cache.
45 * Usually getInstance() is more appropriate.</p>
46 *
47 */
48 public HashMapFeedInfoCache() {
49 setInfoCache(Collections.synchronizedMap(new HashMap()));
50 }
51
52 /***
53 * Get the global instance of the cache
54 * @return an implementation of FeedFetcherCache
55 */
56 public static synchronized FeedFetcherCache getInstance() {
57 if (_instance == null) {
58 _instance = new HashMapFeedInfoCache();
59 }
60 return _instance;
61 }
62
63 protected Object get(Object key) {
64 return infoCache.get(key);
65 }
66
67 /***
68 * @see extensions.io.FeedFetcherCache#getFeedInfo(java.net.URL)
69 */
70 public SyndFeedInfo getFeedInfo(URL feedUrl) {
71 return (SyndFeedInfo) get(feedUrl);
72 }
73
74 protected void put(Object key, Object value) {
75 infoCache.put(key, value);
76 }
77
78 /***
79 * @see extensions.io.FeedFetcherCache#setFeedInfo(java.net.URL, extensions.io.SyndFeedInfo)
80 */
81 public void setFeedInfo(URL feedUrl, SyndFeedInfo syndFeedInfo) {
82 put(feedUrl, syndFeedInfo);
83 }
84
85 protected Map getInfoCache() {
86 return infoCache;
87 }
88
89 protected void setInfoCache(Map map) {
90 infoCache = map;
91 }
92
93 }