Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

ExpiryPolicy on existing caches lost after calling getCache on non-existing cache #51

Open
rogerkl opened this issue Sep 22, 2015 · 3 comments

Comments

@rogerkl
Copy link

rogerkl commented Sep 22, 2015

Had a problem with caches that seem to loose their expiry information.
Tracked down the problem to be caused by calling getCache on a non-existing cache.
It was used to check if the cache existed and if not, create it.

It looks like when JCacheManager.getCache() are not finding a cache in allCaches it
calls refreshallCaches() which will recreate them, but the expiry-configuration seems to be lost.

This test will show the error as the last assert will fail because the expiry-policy is lost.

@Test
public void testRefreshAllCachesError() {
    final CachingProvider cachingProvider = Caching.getCachingProvider();
    final CacheManager cacheManager = cachingProvider.getCacheManager();

    String cacheNameExisting = "existingCache";
    String cacheNameNonExisting = "nonExistingCache";

    MutableConfiguration configuration = new MutableConfiguration();
    configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 60)));

    configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 60)));
    cacheManager.createCache(cacheNameExisting, new JCacheConfiguration(configuration));

    Cache<Object, Object> sampleCache = cacheManager.getCache(cacheNameExisting);
    assertNotNull(sampleCache);
    assertThat(sampleCache.getConfiguration(JCacheConfiguration.class).getExpiryPolicy().getExpiryForCreation().getDurationAmount(), is(60l));

    // this will trigger refreshAllCaches which recreates caches
    assertNull(cacheManager.getCache(cacheNameNonExisting));

    // existing cache is OK but ...
    assertThat(sampleCache.getConfiguration(JCacheConfiguration.class).getExpiryPolicy().getExpiryForCreation().getDurationAmount(), is(60l));

    // ... if we fetch it again from cacheManager:
    // this will fail as cache existingCache has been recreated and lost its expiry-policy
    sampleCache = cacheManager.getCache(cacheNameExisting);
    assertThat(sampleCache.getConfiguration(JCacheConfiguration.class).getExpiryPolicy().getExpiryForCreation().getDurationAmount(), is(60l));
}
@jgasda
Copy link

jgasda commented Jul 12, 2017

This issue is now nearly 2 years old - is there a plan to fix it?

@wapophis
Copy link

wapophis commented Jul 5, 2018

Same issue using the Factory pattern to configure the caches using annonattions.

@henri-tremblay
Copy link
Contributor

This project isn't maintained anymore. We have updated the readme to make it clearer. Please consider migrating to Ehcache 3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants