Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 309624 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java (-10 / +27 lines)
Lines 11-16 Link Here
11
package org.eclipse.equinox.internal.p2.updatesite;
11
package org.eclipse.equinox.internal.p2.updatesite;
12
12
13
import java.io.*;
13
import java.io.*;
14
import java.lang.ref.SoftReference;
14
import java.net.*;
15
import java.net.*;
15
import java.util.HashMap;
16
import java.util.HashMap;
16
import java.util.Map;
17
import java.util.Map;
Lines 48-56 Link Here
48
	 * Some variables for caching.
49
	 * Some variables for caching.
49
	 */
50
	 */
50
	// map of String (URI.toString()) to UpdateSite
51
	// map of String (URI.toString()) to UpdateSite
51
	private static Map<String, UpdateSite> siteCache = new HashMap<String, UpdateSite>();
52
	private static Map<String, SoftReference<UpdateSite>> siteCache = new HashMap<String, SoftReference<UpdateSite>>();
52
	// map of String (URI.toString()) to UpdateSite (for category xmls)
53
	// map of String (URI.toString()) to UpdateSite (for category xmls)
53
	private static Map<String, UpdateSite> categoryCache = new HashMap<String, UpdateSite>();
54
	private static Map<String, SoftReference<UpdateSite>> categoryCache = new HashMap<String, SoftReference<UpdateSite>>();
54
	// map of String (featureID_featureVersion) to Feature
55
	// map of String (featureID_featureVersion) to Feature
55
	private Map<String, Feature> featureCache = new HashMap<String, Feature>();
56
	private Map<String, Feature> featureCache = new HashMap<String, Feature>();
56
57
Lines 81-89 Link Here
81
	public static synchronized UpdateSite loadCategoryFile(URI location, IProgressMonitor monitor) throws ProvisionException {
82
	public static synchronized UpdateSite loadCategoryFile(URI location, IProgressMonitor monitor) throws ProvisionException {
82
		if (location == null)
83
		if (location == null)
83
			return null;
84
			return null;
84
		UpdateSite result = categoryCache.get(location.toString());
85
		UpdateSite result = null;
85
		if (result != null)
86
		if (!PROTOCOL_FILE.equals(location.getScheme()) && categoryCache.containsKey(location.toString())) {
86
			return result;
87
			result = categoryCache.get(location.toString()).get();
88
			if (result != null)
89
				return result;
90
			//else soft reference has been cleared, take it out of the cache
91
			categoryCache.remove(location.toString());
92
		}
93
87
		InputStream input = null;
94
		InputStream input = null;
88
		File siteFile = loadActualSiteFile(location, location, monitor);
95
		File siteFile = loadActualSiteFile(location, location, monitor);
89
		try {
96
		try {
Lines 93-99 Link Here
93
			SiteModel siteModel = siteParser.parse(input);
100
			SiteModel siteModel = siteParser.parse(input);
94
			String checksumString = Long.toString(checksum.getValue());
101
			String checksumString = Long.toString(checksum.getValue());
95
			result = new UpdateSite(siteModel, location, checksumString);
102
			result = new UpdateSite(siteModel, location, checksumString);
96
			categoryCache.put(location.toString(), result);
103
			if (!PROTOCOL_FILE.equals(location.getScheme()))
104
				categoryCache.put(location.toString(), new SoftReference<UpdateSite>(result));
97
			return result;
105
			return result;
98
		} catch (SAXException e) {
106
		} catch (SAXException e) {
99
			String msg = NLS.bind(Messages.ErrorReadingSite, location);
107
			String msg = NLS.bind(Messages.ErrorReadingSite, location);
Lines 119-127 Link Here
119
	public static synchronized UpdateSite load(URI location, IProgressMonitor monitor) throws ProvisionException {
127
	public static synchronized UpdateSite load(URI location, IProgressMonitor monitor) throws ProvisionException {
120
		if (location == null)
128
		if (location == null)
121
			return null;
129
			return null;
122
		UpdateSite result = siteCache.get(location.toString());
130
123
		if (result != null)
131
		UpdateSite result = null;
124
			return result;
132
		//only caching remote sites
133
		if (!PROTOCOL_FILE.equals(location.getScheme()) && siteCache.containsKey(location.toString())) {
134
			result = siteCache.get(location.toString()).get();
135
			if (result != null)
136
				return result;
137
			//else soft reference has been cleared, take it out of the cache
138
			siteCache.remove(location.toString());
139
		}
140
125
		InputStream input = null;
141
		InputStream input = null;
126
		File siteFile = loadSiteFile(location, monitor);
142
		File siteFile = loadSiteFile(location, monitor);
127
		try {
143
		try {
Lines 131-137 Link Here
131
			SiteModel siteModel = siteParser.parse(input);
147
			SiteModel siteModel = siteParser.parse(input);
132
			String checksumString = Long.toString(checksum.getValue());
148
			String checksumString = Long.toString(checksum.getValue());
133
			result = new UpdateSite(siteModel, getSiteURI(location), checksumString);
149
			result = new UpdateSite(siteModel, getSiteURI(location), checksumString);
134
			siteCache.put(location.toString(), result);
150
			if (!PROTOCOL_FILE.equals(location.getScheme()))
151
				siteCache.put(location.toString(), new SoftReference<UpdateSite>(result));
135
			return result;
152
			return result;
136
		} catch (SAXException e) {
153
		} catch (SAXException e) {
137
			String msg = NLS.bind(Messages.ErrorReadingSite, location);
154
			String msg = NLS.bind(Messages.ErrorReadingSite, location);

Return to bug 309624