<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=nugs" rel="nofollow">Andrew Walters</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8992?redirect=false" rel="nofollow">SPR-8992</a></strong> and commented</p>
<p dir="auto">Given:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles(profiles = &quot;test&quot;)
@ContextConfiguration(classes = MyClass.class)
@ImportResource(&quot;/appContext.xml&quot;)
public class MyClass {
  @Autowired
  private ProfileSpecificResource resource;

  @Bean
  public String aBean() {...}

  @Test
  public void aTest() {...}
}"><pre class="notranslate"><code class="notranslate">@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles(profiles = "test")
@ContextConfiguration(classes = MyClass.class)
@ImportResource("/appContext.xml")
public class MyClass {
  @Autowired
  private ProfileSpecificResource resource;

  @Bean
  public String aBean() {...}

  @Test
  public void aTest() {...}
}
</code></pre></div>
<p dir="auto">Spring is not cascading/passing through the active profile(s) down to the imported resource (where profile specific beans are defined).</p>
<p dir="auto">If the tests are invoked with the -Dspring.profiles.active=test argument, the tests run as expected.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 GA</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398116795" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13685" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13685/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13685">#13685</a> <code class="notranslate">@ActiveProfiles</code> not taken into account for <code class="notranslate">@ImportResource-imported</code> XML context definitions from an <code class="notranslate">@Configuration</code> context definition (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112653" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13040" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13040/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13040">#13040</a> AnnotatedBeanDefinitionReader's constructor should inherit Environment of supplied BeanDefinitionRegistry</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/ee36c80ca961a5b2af233cd26a5483d57939c0af/hovercard" href="https://github.com/spring-projects/spring-framework/commit/ee36c80ca961a5b2af233cd26a5483d57939c0af"><tt>ee36c80</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/b17d545bb71b51ae46689a88487898dac496544c/hovercard" href="https://github.com/spring-projects/spring-framework/commit/b17d545bb71b51ae46689a88487898dac496544c"><tt>b17d545</tt></a></p>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=olivergierke" rel="nofollow">Oliver Drotbohm</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9254?redirect=false" rel="nofollow">SPR-9254</a></strong> and commented</p>
<p dir="auto">Imagine the following usage of the cache abstraction:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class MyComponent implements Component {

  @Cacheable(&quot;myCache&quot;)
  public Object myMethod(String key) {

  }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">MyComponent</span> <span class="pl-k">implements</span> <span class="pl-smi">Component</span> {

  <span class="pl-c1">@</span><span class="pl-c1">Cacheable</span>(<span class="pl-s">"myCache"</span>)
  <span class="pl-k">public</span> <span class="pl-smi">Object</span> <span class="pl-en">myMethod</span>(<span class="pl-smi">String</span> <span class="pl-s1">key</span>) {

  }
}</pre></div>
<p dir="auto">Now assume the execution of <code class="notranslate">myMethod(...)</code> takes a huge amount of time (hence the caching in the first place). Now futher assume we access the method concurrently with two threads. With the current implementation of the cache interceptor works as follows:</p>
<ul dir="auto">
<li>thread 1 triggers the interceptor, we don't find a value for the key in the cache and thus invoke the method.</li>
<li>Now while the method invocation in thread 1 runs, thread 2 enters the interceptor with the same key, we don't find a value and <strong>re-trigger the method</strong> call</li>
</ul>
<p dir="auto">This is unfortunate as the second invocation is entirely obsolete as the second thread could just wait for the first invocation to succeed and use the value returned. Beyond that we might face this scenario in extended version as while the first thread calculates the value pretty much all threads invoking the method with the same key would re-trigger the calculation. So the longer the value calculation takes the more likely we will run into unnecessary duplicate invocations of the method.</p>
<p dir="auto">So what I am suggesting is that we should keep track of actual method invocations by key and block all concurrent accesses to that cache value until the first thread calculating it has finished and let the other threads use that value then. The <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilder.html" rel="nofollow"><code class="notranslate">CacheBuilder</code> API</a> of the Google Guava project actually implements this out of the box.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398118520" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13942" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13942/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13942">#13942</a> Provide some synchronization between <code class="notranslate">@Cacheable</code> and <code class="notranslate">@CacheEvict</code> annotated methods</li>
<li><a href="https://jira.spring.io/browse/DATAREDIS-443" rel="nofollow">DATAREDIS-443</a> Support of synchronized mode introduced in Spring 4.3</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398166405" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/16165" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/16165/hovercard" href="https://github.com/spring-projects/spring-framework/issues/16165">#16165</a> Support of ehcache's BlockingCache</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398188019" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/18383" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/18383/hovercard" href="https://github.com/spring-projects/spring-framework/issues/18383">#18383</a> Better synchronization in ConcurrentMapCache</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398192832" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/18804" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/18804/hovercard" href="https://github.com/spring-projects/spring-framework/issues/18804">#18804</a> Allow <code class="notranslate">@Cacheable</code> method to return java.util.Optional variant of cached value</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-data-redis/commit/1f97623a7ca52b9706488efa86e817983214c305/hovercard" href="https://github.com/spring-projects/spring-data-redis/commit/1f97623a7ca52b9706488efa86e817983214c305">spring-projects/spring-data-redis@<tt>1f97623</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-data-redis/commit/ceccafb6706a137713f376425a826c203a947814/hovercard" href="https://github.com/spring-projects/spring-data-redis/commit/ceccafb6706a137713f376425a826c203a947814">spring-projects/spring-data-redis@<tt>ceccafb</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-data-redis/commit/5cc5da919937625f21cb03141e92aa0ed3bbca50/hovercard" href="https://github.com/spring-projects/spring-data-redis/commit/5cc5da919937625f21cb03141e92aa0ed3bbca50">spring-projects/spring-data-redis@<tt>5cc5da9</tt></a>, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-data-redis/commit/a03c4442988b22a2d3a28196828e04a7daf9427d/hovercard" href="https://github.com/spring-projects/spring-data-redis/commit/a03c4442988b22a2d3a28196828e04a7daf9427d">spring-projects/spring-data-redis@<tt>a03c444</tt></a></p>
<p dir="auto">17 votes, 25 watchers</p>