|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2009 the original author or authors. |
| 2 | + * Copyright 2002-2011 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.cache.ehcache;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
| 20 | +import java.io.InputStream; |
20 | 21 |
|
21 | 22 | import net.sf.ehcache.CacheException;
|
22 | 23 | import net.sf.ehcache.CacheManager;
|
@@ -97,23 +98,17 @@ public void setCacheManagerName(String cacheManagerName) {
|
97 | 98 |
|
98 | 99 | public void afterPropertiesSet() throws IOException, CacheException {
|
99 | 100 | logger.info("Initializing EHCache CacheManager");
|
100 |
| - if (this.shared) { |
101 |
| - // Shared CacheManager singleton at the VM level. |
102 |
| - if (this.configLocation != null) { |
103 |
| - this.cacheManager = CacheManager.create(this.configLocation.getInputStream()); |
| 101 | + if (this.configLocation != null) { |
| 102 | + InputStream is = this.configLocation.getInputStream(); |
| 103 | + try { |
| 104 | + this.cacheManager = (this.shared ? CacheManager.create(is) : new CacheManager(is)); |
104 | 105 | }
|
105 |
| - else { |
106 |
| - this.cacheManager = CacheManager.create(); |
| 106 | + finally { |
| 107 | + is.close(); |
107 | 108 | }
|
108 | 109 | }
|
109 | 110 | else {
|
110 |
| - // Independent CacheManager instance (the default). |
111 |
| - if (this.configLocation != null) { |
112 |
| - this.cacheManager = new CacheManager(this.configLocation.getInputStream()); |
113 |
| - } |
114 |
| - else { |
115 |
| - this.cacheManager = new CacheManager(); |
116 |
| - } |
| 111 | + this.cacheManager = (this.shared ? CacheManager.create() : new CacheManager()); |
117 | 112 | }
|
118 | 113 | if (this.cacheManagerName != null) {
|
119 | 114 | this.cacheManager.setName(this.cacheManagerName);
|
|
0 commit comments